#include<iostream>
#include<queue>

#define fs first
#define sc second
using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> P2;

int x,y;
int mas[50][50][50][50];
int depart[50][50];
int ax,ay,bx,by;

int main(){
  for(;;){
    cin >> x >> y;
    if(!x && !y)break;

    cin >> ax >> ay >> bx >> by;

    for(int i=0;i<y;i++)
      for(int j=0;j<x;j++){
	cin >> depart[i][j];
	for(int k=0;k<y;k++)
	  for(int l=0;l<x;l++)mas[i][j][k][l] = -1;
      }

    mas[ay-1][ax-1][by-1][bx-1] = 0;
    queue<P2> q;
    q.push(P2(P(ay-1,ax-1),P(by-1,bx-1)));

    int ans = -1;
    while(q.size()){
      P2 p = q.front();q.pop();
      int ky = p.fs.fs, kx = p.fs.sc;
      int ty = p.sc.fs, tx = p.sc.sc;
      //cout << ky << " " << kx << " " << ty << " " << tx<< endl;
      if(ky==ty && kx==tx){
	ans = mas[ky][kx][ty][tx];
	break;
      }
      if(mas[ky][kx][ty][tx]>=100)break;

      int dx[] = {0,1,0,-1},dy[] = {-1,0,1,0};
      for(int i=0;i<4;i++){
	int sky = ky+dy[i], skx = kx+dx[i];
	int sty = ty-dy[i], stx = tx-dx[i];
	bool f1 = (sky<0 || skx<0 || y<=sky || x<=skx || depart[sky][skx]);
	bool f2 = (sty<0 || stx<0 || y<=sty || x<=stx || depart[sty][stx]);
	if(f1 && f2)continue;
	if(f1 && !f2){
	  sky = ky;
	  skx = kx;
	}
	if(!f1 && f2){
	  sty = ty;
	  stx = tx;
	}
	if(mas[sky][skx][sty][stx]>=0)continue;
	mas[sky][skx][sty][stx] = mas[ky][kx][ty][tx] + 1;
	q.push(P2(P(sky,skx),P(sty,stx)));
      }
    }
    if(ans<0)cout << "NA\n";
    else cout << ans << endl;
  }
}