#include<iostream>
#define M 52
#include<queue>
#include<cstring>
using namespace std;
struct P{
	int ax,ay,bx,by,cost;
	P(){}
	P(int h,int j,int k,int l,int co):
	ax(h),ay(j),bx(k),by(l),cost(co){}
};
int main(){
	bool s[M][M],d[M][M][M][M],u;
	int w,h,tx,ty,kx,ky,dx[]={1,-1,0,0},dy[]={0,0,-1,1};
	while(cin>>w>>h,w||h){
		cin>>tx>>ty;tx--;ty--;
		cin>>kx>>ky;kx--;ky--;
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				cin>>s[i][j];
		queue<P> que;
		memset(d,0,sizeof(d));
		d[tx][ty][kx][ky]=1;
		que.push(P(tx,ty,kx,ky,0));
		u=true;
		while(!que.empty()){
			P p=que.front();
			que.pop();
			if(p.cost>=100)
				break;
			if(p.ax==p.bx&&p.ay==p.by){
				cout<<p.cost<<endl;
				u=false;
				break;
			}
			int ntx,nty,nkx,nky;
			for(int i=0;i<4;i++){
				ntx=p.ax+dx[i];
				nty=p.ay+dy[i];
				nkx=p.bx-dx[i];
				nky=p.by-dy[i];
				if(!(ntx>=0&&ntx<w&&nty>=0&&nty<h)||s[nty][ntx]==1){
					ntx=p.ax;nty=p.ay;
				}
				if(!(nkx>=0&&nkx<w&&nky>=0&&nky<h)||s[nky][nkx]==1){
					nkx=p.bx;nky=p.by;
				}
				if(d[ntx][nty][nkx][nky]!=1)
					que.push(P(ntx,nty,nkx,nky,p.cost+1));
				d[ntx][nty][nkx][nky]=1;
			}
		}
		if(u)
		cout<<"NA"<<endl;
	}
	return 0;
}