#include <cstdio>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii;
typedef tuple<pii,pii,int> T;
int M[51][51],dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int main(){
	int a,b,x,y,X,Y,i,j;
	for(;scanf("%d%d",&a,&b),a;){
		map<pair<pii,pii>,int>m;
		scanf("%d%d%d%d",&x,&y,&X,&Y);x--,y--,X--,Y--;
		for(j=0;j<b;j++)for(i=0;i<a;i++)scanf("%d",M[i]+j);
		queue<T>q;
		m[make_pair(make_pair(x,y),make_pair(X,Y))]=1;
		for(q.push(make_tuple(make_pair(x,y),make_pair(X,Y),0));!q.empty();){
			T z=q.front();q.pop();
			if(get<0>(z)==get<1>(z)){printf("%d\n",get<2>(z));goto OK;}
			if(get<2>(z)>=99)continue;
			for(i=0;i<4;i++){
				pii c1=make_pair(get<0>(z).first+dx[i],get<0>(z).second+dy[i]);
				if(!(0<=c1.first&&c1.first<a&&0<=c1.second&&c1.second<b&&!M[c1.first][c1.second]))c1=get<0>(z);
				pii c2=make_pair(get<1>(z).first+dx[(i+2)%4],get<1>(z).second+dy[(i+2)%4]);
				if(!(0<=c2.first&&c2.first<a&&0<=c2.second&&c2.second<b&&!M[c2.first][c2.second]))c2=get<1>(z);
				if((c1!=get<0>(z)||c2!=get<1>(z))&&!m[make_pair(c1,c2)]){
					q.push(make_tuple(c1,c2,get<2>(z)+1));
					m[make_pair(c1,c2)]=1;
				}
			}
		}
		puts("NA");
		OK:;
	}
}