{"raw_statement":[{"iden":"problem statement","content":"A maze is composed of a grid of $H \\times W$ squares - $H$ vertical, $W$ horizontal.\nThe square at the $i$\\-th row from the top and the $j$\\-th column from the left - $(i,j)$ - is a wall if $S_{ij}$ is `#` and a road if $S_{ij}$ is `.`.\nThere is a magician in $(C_h,C_w)$. He can do the following two kinds of moves:\n\n*   Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.\n*   Move B: Use magic to warp himself to a road square in the $5\\times 5$ area centered at the square he is currently in.\n\nIn either case, he cannot go out of the maze.\nAt least how many times does he need to use the magic to reach $(D_h, D_w)$?"},{"iden":"constraints","content":"*   $1 \\leq H,W \\leq 10^3$\n*   $1 \\leq C_h,D_h \\leq H$\n*   $1 \\leq C_w,D_w \\leq W$\n*   $S_{ij}$ is `#` or `.`.\n*   $S_{C_h C_w}$ and $S_{D_h D_w}$ are `.`.\n*   $(C_h,C_w) \\neq (D_h,D_w)$"},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$H$ $W$\n$C_h$ $C_w$\n$D_h$ $D_w$\n$S_{11}\\ldots S_{1W}$\n$\\vdots$\n$S_{H1}\\ldots S_{HW}$"},{"iden":"sample input 1","content":"4 4\n1 1\n4 4\n..#.\n..#.\n.#..\n.#.."},{"iden":"sample output 1","content":"1\n\nFor example, by walking to $(2,2)$ and then using the magic to travel to $(4,4)$, just one use of magic is enough.\nNote that he cannot walk diagonally."},{"iden":"sample input 2","content":"4 4\n1 4\n4 1\n.##.\n####\n####\n.##."},{"iden":"sample output 2","content":"\\-1\n\nHe cannot move from there."},{"iden":"sample input 3","content":"4 4\n2 2\n3 3\n....\n....\n....\n...."},{"iden":"sample output 3","content":"0\n\nNo use of magic is needed."},{"iden":"sample input 4","content":"4 5\n1 2\n2 5\n#.###\n####.\n#..##\n#..##"},{"iden":"sample output 4","content":"2"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}