#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};

struct State { int tx, ty, kx, ky, cost; };
int X, Y;
int d[52][52];
bool used[52][52][52][52];

int main() {
    while (cin >> X >> Y, X) {
        int tx, ty, kx, ky;
        cin >> tx >> ty >> kx >> ky;
        for (int i=0; i<=Y+1; ++i) {
            for (int j=0; j<=X+1; ++j) {
                if (i==0 || i==Y+1 || j==0 || j==X+1) d[i][j] = 1;
                else cin >> d[i][j];
            }
        }
        memset(used, false, sizeof used);
        queue<State> q;
        q.push((State){tx, ty, kx, ky, 0});
        int res = -1;
        while ( ! q.empty()) {
            State s = q.front(); q.pop();
            if (used[s.tx][s.ty][s.kx][s.ky]) continue;
            used[s.tx][s.ty][s.kx][s.ky] = true;
            if (s.tx == s.kx && s.ty == s.ky) {
                res = s.cost;
                break;
            }
            for (int i=0; i<4; ++i) {
                if (d[s.ty+dy[i]][s.tx+dx[i]] && d[s.ky-dy[i]][s.kx-dx[i]]) continue;
                int tx2 = s.tx, ty2 = s.ty;
                if ( ! d[s.ty+dy[i]][s.tx+dx[i]]) {
                    tx2 += dx[i];
                    ty2 += dy[i];
                }
                int kx2 = s.kx, ky2 = s.ky;
                if ( ! d[s.ky-dy[i]][s.kx-dx[i]]) {
                    kx2 -= dx[i];
                    ky2 -= dy[i];
                }
                q.push((State){tx2, ty2, kx2, ky2, s.cost+1});
            }
        }
        if (res < 0) {
            cout << "NA" << endl;
        } else {
            cout << res << endl;
        }
    }
    return 0;
}