#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int h[60][60][60][60];
int main(){
	int n,m;
	while(cin>>m>>n,n||m){
		rep(i,60)rep(j,60)rep(k,60)rep(l,60)h[i][j][k][l]=false;
		int sx,sy,gx,gy;
		cin>>sy>>sx>>gy>>gx;
		vvi in(n+2,vi(m+2,1));
		rep(i,n)rep(j,m)cin>>in[i+1][j+1];
		queue<pair<pii,pii> >q;
		q.push(pair<pii,pii>(pii(sx,sy),pii(gx,gy)));
		h[sx][sy][gx][gy]=true;
		int out=0;
		while(1){
			out++;
			queue<pair<pii,pii> >nex;
			while(q.size()){
				pair<pii,pii>now=q.front();q.pop();
				pii ta=now.first,ka=now.second;
				rep(i,4){
					int tx=ta.first+dx[i],ty=ta.second+dy[i];
					int kx=ka.first+dx[(i+2)%4],ky=ka.second+dy[(i+2)%4];
					if(in[tx][ty]==1){
						tx-=dx[i];ty-=dy[i];
					}
					if(in[kx][ky]==1){
						kx-=dx[(i+2)%4];ky-=dy[(i+2)%4];
					}
					if(kx==tx&&ky==ty)goto end;
					if(h[tx][ty][kx][ky])continue;
					h[tx][ty][kx][ky]=true;
					nex.push(pair<pii,pii>(pii(tx,ty),pii(kx,ky)));
				}
			}
			q=nex;
			if(q.size()==0){
				cout<<"NA"<<endl;
				goto br;
			}
		}
		end:;
		cout<<out<<endl;
		br:;
	}
}