{"raw_statement":[{"iden":"problem statement","content":"There is a skating rink represented by a grid with $H$ horizontal rows and $W$ vertical columns. Let $(i, j)$ denote the square at the $i$\\-th row from the top and $j$\\-th column from the left.\nThe skating rink has $N$ obstacles. The $i$\\-th obstacle is placed at $(X_i,Y_i)$.\nIn a single move, Takahashi chooses one of the four directions, up, down, left, or right, and keeps moving until he hits an obstacle.  \nWhen he hits an obstacle, he stops at the square right before the obstacle. Since the skating rink is surrounded by cliffs, it is prohibited to start a move in which he will never hit an obstacle.\nTakahashi is initially at $(s_x,s_y)$. He wants to make some number of moves to stop at $(g_x,g_y)$.\nFind the minimum number of moves required to end up at $(g_x, g_y)$. If it is not possible, report the fact."},{"iden":"constraints","content":"*   $1\\leq H \\leq 10^9$\n*   $1\\leq W \\leq 10^9$\n*   $1\\leq N \\leq 10^5$\n*   $1\\leq s_x,g_x\\leq H$\n*   $1\\leq s_y,g_y\\leq W$\n*   $1\\leq X_i \\leq H$\n*   $1\\leq Y_i \\leq W$\n*   $(s_x,s_y)\\neq (g_x,g_y)$\n*   $(s_x,s_y)\\neq (X_i,Y_i)$\n*   $(g_x,g_y)\\neq (X_i,Y_i)$\n*   If $i\\neq j$, then $(X_i,Y_i)\\neq (X_j,Y_j)$.\n*   All values in input are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$H$ $W$ $N$\n$s_x$ $s_y$\n$g_x$ $g_y$\n$X_1$ $Y_1$\n$X_2$ $Y_2$\n$\\vdots$\n$X_N$ $Y_N$"},{"iden":"sample input 1","content":"7 8 7\n3 4\n5 6\n1 4\n2 1\n2 8\n4 5\n5 7\n6 2\n6 6"},{"iden":"sample output 1","content":"4\n\n![image](https://img.atcoder.jp/ghi/c376ca3813eb4c947eb605dea2d30454.png)\nIn the figure, $(s_x,s_y)$ is denoted by `S` and $(g_x,g_y)$ is denoted by `G`.  \nBy moving as $(3,4)\\rightarrow(2,4) \\rightarrow(2,2) \\rightarrow(5,2) \\rightarrow(5,6)$, he can end up at $(g_x,g_y)$ with $4$ moves."},{"iden":"sample input 2","content":"4 6 2\n3 2\n3 5\n4 5\n2 5"},{"iden":"sample output 2","content":"\\-1\n\n![image](https://img.atcoder.jp/ghi/07ab8a3e7c94525cd52704dd43e43b87.png)\nHe must stop at $(g_x,g_y)$.  \nNote that just passing through $(g_x,g_y)$ is not considered to be ending up at the goal."},{"iden":"sample input 3","content":"1 10 1\n1 5\n1 1\n1 7"},{"iden":"sample output 3","content":"\\-1\n\n![image](https://img.atcoder.jp/ghi/a423524262f4a075b94e2ab5f9e61164.png)  \nIf he chooses to move to the left, Takahashi will fall down the cliff after passing through $(g_x,g_y)$.  \nNote that it is prohibited to start a move in which he will never hit an obstacle, as the skating rink is surrounded by cliffs."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}