#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

#define fst first
#define scd second
#define mp make_pair
#define rep(i,x) for(int i=0;i<(int)x;++i)
#define rep1(i,x) for(int i=1;i<=(int)x;++i)

class P {
public:
    int x, y;
    P (int x0,int y0) {
        x=x0,y=y0;
    };
};

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

int d[53][53];
int memo[53][53][53][53];
bool used[53][53][53][53];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int X, Y;
    while (cin >> X >> Y, X || Y) {
        memset(memo, 0, sizeof(memo));
        memset(used, false, sizeof(used));

        int tx, ty; cin >> tx >> ty;
        int kx, ky; cin >> kx >> ky;
        fill(d[0], d[Y+2], 1);
        rep1(i, Y) rep1(j, X) cin >> d[i][j];

        queue<pair<P, P> > q;

        q.push(mp(P(tx, ty), P(kx, ky)));
        memo[ty][tx][ky][kx] = 0;
        used[ty][tx][ky][kx] = true;

        int ans = -1;

        while (q.size()) {
            pair<P, P> r = q.front(); q.pop();
            P f = r.fst, s = r.scd;

            if (memo[f.y][f.x][s.y][s.x] >= 100) break;

            if (f.x == s.x && f.y == s.y) {
                ans = memo[f.y][f.x][s.y][s.x];
                break;
            }

            rep(i, 4) {
                int nfx = f.x + dx[i], nfy = f.y + dy[i];
                int nsx = s.x - dx[i], nsy = s.y - dy[i];
                if (d[nfy][nfx] == 1) nfx = f.x, nfy = f.y;
                if (d[nsy][nsx] == 1) nsx = s.x, nsy = s.y;
                if (!used[nfy][nfx][nsy][nsx]) {
                    used[nfy][nfx][nsy][nsx] = true;
                    memo[nfy][nfx][nsy][nsx] = memo[f.y][f.x][s.y][s.x] + 1;
                    q.push(mp(P(nfx, nfy), P(nsx, nsy)));
                }
            }
        }

        if (ans == -1) cout << "NA" << endl;
        else cout << ans << endl;
    }
}