#include <iostream>
#include <queue>
#include <set>
using namespace std;

class Node {
public:
  int tx, ty;
  int kx, ky;
  int time;
  Node(int tx = 0, int ty = 0, int kx = 0, int ky = 0, int time = 0):
    tx(tx), ty(ty), kx(kx), ky(ky), time(time) {}

  bool operator <(const Node &n) const {
    if(tx != n.tx) return tx < n.tx;
    if(ty != n.ty) return ty < n.ty;
    if(kx != n.kx) return kx < n.kx;
    if(ky != n.ky) return ky < n.ky;
    return false;
  }
};

int main() {
  while(1) {
    int X, Y;
    cin >> X >> Y;
    if(X == 0 && Y == 0) break;
    int tx, ty;
    cin >> tx >> ty;
    int kx, ky;
    cin >> kx >> ky;
    int data[Y][X];
    for(int i = 0; i < Y; i++) {
      for(int j = 0; j < X; j++) {
	cin >> data[i][j];
      }
    }
    queue<Node> Q;
    set<Node> visited;
    Q.push(Node(tx-1, ty-1, kx-1, ky-1, 0));
    int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
    int ans = -1;
    while(!Q.empty()) {
      Node n = Q.front();
      Q.pop();
      if(visited.find(n) != visited.end()) continue;
      visited.insert(n);
      if(n.tx == n.kx && n.ty == n.ky) {
	ans = n.time;
	break;
      }
      for(int i = 0; i < 4; i++) {
	int ntx = n.tx + d[i][0];
	int nty = n.ty + d[i][1];
	if(ntx < 0 || ntx >= X) ntx = n.tx;
	if(nty < 0 || nty >= Y) nty = n.ty;
	if(data[nty][ntx] == 1) {
	  ntx = n.tx;
	  nty = n.ty;
	}
	int nkx = n.kx - d[i][0];
	int nky = n.ky - d[i][1];
	if(nkx < 0 || nkx >= X) nkx = n.kx;
	if(nky < 0 || nky >= Y) nky = n.ky;
	if(data[nky][nkx] == 1) {
	  nkx = n.kx;
	  nky = n.ky;
	}
	if(visited.find(Node(ntx, nty, nkx, nky, n.time+1)) == visited.end())
	  Q.push(Node(ntx, nty, nkx, nky, n.time+1));
      }
    }
    if(ans == -1) {
      cout << "NA" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}