#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
struct NODE{
	int x1,y1,x2,y2,d;
	NODE(int a,int b,int c,int D,int e){
		x1 = a , y1 = b , x2 = c , y2 = D , d = e;
	}
};
bool done[52][52][52][52] = {0};
bool data[52][52];
int main(){
	int W,H;
	while(cin >> W >> H , W){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		rep(i,52)rep(j,52)data[i][j] = true;
		rep(i,H)rep(j,W)cin >> data[i+1][j+1];
		queue<NODE> Q;
		Q.push(NODE(a,b,c,d,0));
		int ans = -1;
		rep(i,52)rep(j,52)rep(k,52)rep(l,52)
			done[i][j][k][l] = 0;
		
		while(Q.size()){
			NODE q = Q.front(); Q.pop();
			if(q.d >= 100) break;
			if(done[q.y1][q.x1][q.y2][q.x2])continue;
			else done[q.y1][q.x1][q.y2][q.x2] = true;
			
			if(q.x1 == q.x2 && q.y1 == q.y2){
				ans = q.d;
				break;
			}
			rep(i,4){
				int A = q.x1 + dx[i] , B = q.y1 + dy[i];
				int C = q.x2 - dx[i] , D = q.y2 - dy[i];
				if(data[B][A])A = q.x1 , B = q.y1;
				if(data[D][C])C = q.x2 , D = q.y2;
				Q.push(NODE(A,B,C,D,q.d+1));
			}
		}
		if(~ans){
			cout << ans << endl;
		}else{
			cout << "NA" << endl;
		}
	}
}