#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int X,Y,tx,ty,kx,ky;
int wall[50][50];
bool vis[50][50][50][50];

typedef struct _node{
  int cost,tx,ty,kx,ky;
  int geth()const{
    return (abs(tx-kx)+abs(ty-ky))/2;
  }
  bool operator<(const _node& r)const{
    return cost+geth()>r.cost+r.geth();
  }
  _node (int c,int atx,int aty,int akx,int aky){
    cost=c;
    tx=atx;
    ty=aty;
    kx=akx;
    ky=aky;
  }
}node;

void solve(){
  scanf("%d%d%d%d",&tx,&ty,&kx,&ky);
  --tx,--ty,--kx,--ky;
  rep(i,Y)rep(j,X)scanf("%d",wall[i]+j);
  
  priority_queue<node>q;
  q.push(node(0,tx,ty,kx,ky));
  memset(vis,0,sizeof(vis));
  while(!q.empty()){
    int cc=q.top().cost;
    tx=q.top().tx;
    ty=q.top().ty;
    kx=q.top().kx;
    ky=q.top().ky;
    int h=q.top().geth();
    q.pop();
    if(cc+h>=100 || vis[tx][ty][kx][ky])continue;
    vis[tx][ty][kx][ky]=true;
    if(tx==kx && ty==ky){
      printf("%d\n",cc);
      return;
    }
    rep(i,4){
      int ntx=tx+dx[i],nty=ty+dy[i];
      int nkx=kx-dx[i],nky=ky-dy[i];

      if(0>ntx || ntx>=X ||
         0>nty || nty>=Y ||
         wall[nty][ntx])ntx=tx,nty=ty;
      if(0>nkx || nkx>=X ||
         0>nky || nky>=Y ||
         wall[nky][nkx])nkx=kx,nky=ky;
      if(vis[ntx][nty][nkx][nky])continue;
      q.push(node(cc+1,ntx,nty,nkx,nky));
    }
  }
  printf("NA\n");
}

int main(){
  while(scanf("%d%d",&X,&Y),X)
    solve();
}