#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <complex>
#include <queue>
#include <deque>
#include <cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
typedef complex<int> cl;
typedef pair<cl,cl> pr;
typedef pair<pr,int> ppr;
typedef vector<pr> vpr;
const int INF=1<<30;
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
bool reached[52][52][52][52]={};
ppr pprs(cl a,cl b,int c){ return ppr(pr(a,b),c);}
int main() {
	// your code goes here
	int X,Y,tmp,tmpb;
	while(cin >> X >> Y && X){
	REP(i,52) REP(j,52) REP(k,52) REP(l,52) reached[i][j][k][l]=false;
	bool maps[52][52]={};
	cl t,k;
	cin >> tmp>> tmpb;
	t=cl(tmpb,tmp);
	cin >> tmp>> tmpb;
	k=cl(tmpb,tmp);
	REP(i,Y+2)
		REP(j,X+2)
				maps[i][j]=1;
	FORE(i,1,Y)
		FORE(j,1,X)
			cin >> maps[i][j];
	queue<ppr> qu;
	qu.push(pprs(t,k,0));
	int ans=-1;
	while(!qu.empty()){
		cl a=qu.front().first.first,b=qu.front().first.second;
		int t=qu.front().second;
		qu.pop();
		if(a==b){
			ans=t;
			break;
		}
		if(reached[a.real()][a.imag()][b.real()][b.imag()]) continue;
		reached[a.real()][a.imag()][b.real()][b.imag()]=1;

		REP(i,4){
			
			cl na=cl(a),nb=cl(b);
			if(!maps[a.real()+dy[i]][a.imag()+dx[i]])
				na+=cl(dy[i],dx[i]);
			if(!maps[b.real()-dy[i]][b.imag()-dx[i]])
				nb-=cl(dy[i],dx[i]);
			if(!reached[na.real()][na.imag()][nb.real()][nb.imag()])
			qu.push(pprs(na,nb,t+1));
		}
	}
	if(ans==-1 || ans>=100)
	cout << "NA" << endl;
	else 
	cout << ans << endl;
	}
	return 0;
}