#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int INF = 1 << 30;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};
int W, H;
int tx, ty;
int kx, ky;
int d[50][50];
int dist[50][50][50][50];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> W >> H, W) {
    cin >> tx >> ty >> kx >> ky;
    tx--, ty--, kx--, ky--;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> d[i][j];
      }
    }
    fill_n((int*)dist, 50 * 50 * 50 * 50, INF);
    dist[ty][tx][ky][kx] = 0;
    using P = tuple<int, int, int, int>;
    queue<P> que;
    que.emplace(ty, tx, ky, kx);
    bool na = true;
    while (!que.empty()) {
      int ay, ax, by, bx;
      tie(ay, ax, by, bx) = que.front(); que.pop();
      if (dist[ay][ax][by][bx] >= 100) break;
      if (pii(ay, ax) == pii(by, bx)) {
        cout << dist[ay][ax][by][bx] << endl;
        na = false;
        break;
      }
      for (int i = 0; i < 4; i++) {
        int any = ay + dy[i];
        int anx = ax + dx[i];
        int bny = by + dy[(i + 2) % 4];
        int bnx = bx + dx[(i + 2) % 4];
        if (any < 0 || any >= H || anx < 0 || anx >= W || d[any][anx]) any = ay, anx = ax;
        if (bny < 0 || bny >= H || bnx < 0 || bnx >= W || d[bny][bnx]) bny = by, bnx = bx;
        if (dist[any][anx][bny][bnx] > dist[ay][ax][by][bx] + 1) {
          dist[any][anx][bny][bnx] = dist[ay][ax][by][bx] + 1;
          que.emplace(any, anx, bny, bnx);
        }
      }
    }
    if (na) cout << "NA" << endl;
  }  

  return 0;
}
