#include <bits/stdc++.h>
using namespace std;

int dist[52][52][52][52];
int fie[52][52];


int W, H;
int tx, ty;
int kx, ky;

struct A {
  int a;
  int b;
  int c;
  int d;
};

int& acc(A a) {
  return dist[a.a][a.b][a.c][a.d];
}

int dd[] = {1, 0, -1, 0};

A mv(A a, int d) {
  A b = a;
  if(fie[a.a + dd[d]][a.b + dd[d ^ 1]] == 0) {
    b.a = a.a + dd[d];
    b.b = a.b + dd[d ^ 1];
  }
  if(fie[a.c + dd[d ^ 2]][a.d + dd[d ^ 3]] == 0) {
    b.c = a.c + dd[d ^ 2];
    b.d = a.d + dd[d ^ 3];
  }
  return b;
}

int solve() {
  cin >> W >> H;
  if(W == 0 && H == 0) return 0;
  cin >> tx >> ty;
  swap(tx, ty);
  cin >> kx >> ky;
  swap(kx, ky);
  for(int i = 0;i <= H + 1;i++) for(int j = 0;j <= W + 1;j++) fie[i][j] = 1;
  for(int i = 1;i <= H;i++) for(int j = 1;j <= W;j++) cin >> fie[i][j];

  for(auto& w: dist) for(auto& x: w) for(auto& y: x) for(auto& z: y) z = -1;

  queue<A> que;
  que.push({tx, ty, kx, ky});
  acc({tx, ty, kx, ky}) = 0;

  while(!que.empty()) {
    A v = que.front();
    if(v.a == v.c && v.b == v.d) {
      cout << acc(v) << endl;
      return 1;
    }
    que.pop();
    for(int i = 0;i < 4;i++) {
      A u = mv(v, i);
      if(acc(u) == -1) {
        acc(u) = acc(v) + 1;
        que.push(u);
      }
    }
  }
  cout << "NA" << endl;
  return 1;
}

int main() {
  while(solve());
}

