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

const int INF = 1 << 29;

struct state {
    int dist;
    int tx, ty, kx, ky;
    state() {}
    state(int a, int b, int c, int d, int e): dist(a), tx(b), ty(c), kx(d), ky(e) {}
};

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

int W, H, tx, ty, kx, ky;
int wall[50][50];

int memo[50][50][50][50];
int& get_memo(state st) {
    return memo[st.tx][st.ty][st.kx][st.ky];
}

state next_state(state st, int d) {
    int ntx = st.tx+dx[d], nty = st.ty+dy[d];
    if (0 <= ntx && ntx < H && 0 <= nty && nty < W &&
            wall[ntx][nty] == 0) {
        st.tx = ntx; st.ty = nty;
    }
    int nkx = st.kx+dx[(d+2)%4], nky = st.ky+dy[(d+2)%4];
    if (0 <= nkx && nkx < H && 0 <= nky && nky < W &&
            wall[nkx][nky] == 0) {
        st.kx = nkx; st.ky = nky;
    }
    st.dist += 1;
    return st;
}


int main() {
    while (true) {
        cin >> W >> H;
        if (W == 0 && H == 0) break;
        cin >> ty >> tx >> ky >> kx;
        --tx; --ty; --kx; --ky;
        for (int j = 0; j < H; ++j) {
            for (int k = 0; k < W; ++k) {
                cin >> wall[j][k];
            }
        }

        queue<state> que;
        que.emplace(0, tx, ty, kx, ky);

        for (int j = 0; j < H; ++j) {
            for (int k = 0; k < W; ++k) {
                for (int l = 0; l < H; ++l) {
                    fill(memo[j][k][l], memo[j][k][l]+W, INF);
                }
            }
        }
        memo[tx][ty][kx][ky] = 0;

        int ans = 101;

        while (!que.empty()) {
            state st = que.front(); que.pop();

            if (st.dist > 100) {
                break;
            }

            if (st.tx == st.kx && st.ty == st.ky) {
                ans = st.dist;
                break;
            }

            for (int d = 0; d < 4; ++d) {
                state nst = next_state(st, d);

                if (nst.dist < get_memo(nst)) {
                    get_memo(nst) = nst.dist;
                    que.emplace(nst);
                }
            }
        }

        if (ans > 100) {
            cout << "NA" << endl;
        } else {
            cout << ans << endl;
        }
    }
    return 0;
}