# Include <stdio. h> # include <string. h >#include <queue >#include <algorithm> # define N 1005 using namespace std; char map [N] [N]; int v [N] [N], d [4] [2] = {-}, {}, {0,-1}, {}; int begin_x, begin_y, end_x, end_y, n, m; struct node {int x, y, step; friend bool operator <(node a, node B) {return. step> B. step ;}}; void bfs () {memset (v, 0, sizeof (v); priority_queue <node> q; node s, temp; s. x = begin_x; s. y = begin _ Y; s. step = 0; v [s. x] [s. y] = 1; q. push (s); while (! Q. empty () {temp = q. top (); q. pop (); if (s. x = end_x & s. y = end_y) {printf ("% d \ n", s. step); return ;}for (int I = 0; I <4; I ++) {s = temp; s. x + = d [I] [0]; s. y + = d [I] [1]; if (s. x <0 | s. x> = n | s. y <0 | s. y> = m | v [s. x] [s. y]) continue; v [s. x] [s. y] = 1; if (map [s. x] [s. y] = '. ') s. step ++; q. push (s) ;}}int main () {int I; while (scanf ("% d", & n, & m) & (n + m) {for (I = 0; I <n; I ++) scanf ("% s", map [I]); scanf ("% d", & begin_x, & begin_y, & end_x, & end_y); begin_x --; begin_y --; end_x --; end_y --; // The coordinates given in the question are bfs () ;}return 0 ;}calculated from 1 ;}