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

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

int memo[60][60][60][60] = {};

int mas[60][60];

typedef struct{
    int cost;
    int tx;
    int ty;
    int kx;
    int ky;
} Data;

Data make_data(int c, int x, int y, int xx, int yy){
    Data d;
    d.cost = c;
    d.ty = y;
    d.tx = x;
    d.ky = yy;
    d.kx = xx;
    return d;
}

int w, h;

bool isMove(int x, int y){
    return 0 <= x && x < w && 0 <= y && y < h && mas[y][x] == 0;
}

int main(){

    while(cin >> w >> h, w != 0 && h != 0){
        int tx, ty;
        int kx, ky;
        cin >> tx >> ty;
        cin >> kx >> ky;

        tx--;
        ty--;
        kx--;
        ky--;

        for(int i = 0;i < h;i++){
            for(int j = 0;j < w;j++){
                cin >> mas[i][j];
            }
        }

        memset(memo, -1, sizeof(memo));

        queue<Data> que;
        que.push(make_data(0, tx, ty, kx, ky));
        while(!que.empty()){
            int cost = que.front().cost;
            tx = que.front().tx;
            ty = que.front().ty;
            kx = que.front().kx;
            ky = que.front().ky;

            que.pop();

            if(cost >= 100){
                continue;
            }

            if(memo[tx][ty][kx][ky] != -1){
                continue;
            }

            memo[tx][ty][kx][ky] = cost;

            cost++;
            for(int i = 0;i < 4;i++){
                int nx = tx + dx[i];
                int ny = ty + dy[i];

                if(!isMove(nx, ny)){
                    nx -= dx[i];
                    ny -= dy[i];
                }

                int mx = kx - dx[i];
                int my = ky - dy[i];

                if(!isMove(mx, my)){
                    mx += dx[i];
                    my += dy[i];
                }

                que.push(make_data(cost, nx, ny, mx, my));
            }

        }

        int ans = INT_MAX;;
        for(int i = 0;i < h;i++){
            for(int j = 0;j < w;j++){
                if(memo[j][i][j][i] != -1){
                    ans = min(ans, memo[j][i][j][i]);
                }
            }
        }

        if(ans == INT_MAX){
            cout << "NA" << endl;
        }else{
            cout << ans << endl;
        }
    }
}

