#include<iostream>
#include<queue>
using namespace std;

bool isnot_table[51][51][51][51];

const int rightmove = 1;
const int leftmove = -1;
const int up = -1;
const int down = 1;

struct Point{
  int x;
  int y;
};

struct DoublePoint{
  Point m;
  Point l;
  int count;
};

int main(){

    while(1){

      int w,h;

      cin >> w >> h;

      if(w==0 && h==0)
        break;

      int table[w+1][h+1];

      DoublePoint bro;

      cin >> bro.m.x >> bro.m.y >> bro.l.x >> bro.l.y;

      bro.count = 0;

      for(int i=1;i<h+1;i++){
        for(int j=1;j<w+1;j++){
          cin >> table[j][i];
        }
      }


      if(bro.m.x == bro.l.x && bro.l.x == bro.l.y){
        cout << 0 << endl;
        continue;
      }


      for(int i=1;i<=w;i++){
        for(int j=1;j<=h;j++){

          if(table[i][j]==0){
            for(int k=1;k<=w;k++){
              for(int p=1;p<=h;p++){

                if(table[k][p]==0){
                  isnot_table[i][j][k][p] = true;
                }
                else{
                  isnot_table[i][j][k][p] = false;
                }

              }
            }
          }
          else{
            for(int k=1;k<=w;k++){
              for(int p=1;p<=h;p++){
                isnot_table[i][j][k][p] = false;
              }
            }
          }

        }
      }

      isnot_table[bro.m.x][bro.m.y][bro.l.x][bro.l.y] = false;

      queue<DoublePoint> q;

      q.push(bro);

      while(!q.empty()){

        DoublePoint BefroreTwin = q.front();

        q.pop();

        BefroreTwin.count++;

        if(BefroreTwin.count >= 100){
          cout << "NA" << endl;
          q.push(BefroreTwin);
          break;
        }

        DoublePoint tmp = BefroreTwin;




        if(table[tmp.m.x+leftmove][tmp.m.y]==0 && tmp.m.x != 1){
          tmp.m.x += leftmove;
        }
        if(table[tmp.l.x+rightmove][tmp.l.y]==0 && tmp.l.x != w){
          tmp.l.x += rightmove;
        }

        if(isnot_table[tmp.m.x][tmp.m.y][tmp.l.x][tmp.l.y]){
          if(tmp.m.x == tmp.l.x && tmp.m.y == tmp.l.y){
            cout << tmp.count << endl;
            q.push(tmp);
            break;
          }
          isnot_table[tmp.m.x][tmp.m.y][tmp.l.x][tmp.l.y] = false;
          q.push(tmp);
        }
        tmp = BefroreTwin;


        if(table[tmp.m.x+rightmove][tmp.m.y]==0 && tmp.m.x != w){
          tmp.m.x += rightmove;
        }
        if(table[tmp.l.x+leftmove][tmp.l.y]==0 && tmp.l.x != 1){
          tmp.l.x += leftmove;
        }

        if(isnot_table[tmp.m.x][tmp.m.y][tmp.l.x][tmp.l.y]){
          if(tmp.m.x == tmp.l.x && tmp.m.y == tmp.l.y){
            cout << tmp.count << endl;
            q.push(tmp);
            break;
          }
          isnot_table[tmp.m.x][tmp.m.y][tmp.l.x][tmp.l.y] = false;
          q.push(tmp);

        }

        tmp = BefroreTwin;


        if(table[tmp.m.x][tmp.m.y+up]==0 && tmp.m.y != 1){
          tmp.m.y += up;
        }
        if(table[tmp.l.x][tmp.l.y+down]==0 && tmp.l.y != h){
          tmp.l.y += down;
        }

        if(isnot_table[tmp.m.x][tmp.m.y][tmp.l.x][tmp.l.y]){
          if(tmp.m.x == tmp.l.x && tmp.m.y == tmp.l.y){
            cout << tmp.count << endl;
            q.push(tmp);
            break;
          }
          isnot_table[tmp.m.x][tmp.m.y][tmp.l.x][tmp.l.y] = false;
          q.push(tmp);
        }

        tmp = BefroreTwin;


        if(table[tmp.m.x][tmp.m.y+down]==0 && tmp.m.y != h){
          tmp.m.y += down;
        }
        if(table[tmp.l.x][tmp.l.y+up]==0 && tmp.l.y != 1){
          tmp.l.y += up;
        }
        
        if(isnot_table[tmp.m.x][tmp.m.y][tmp.l.x][tmp.l.y]){
          if(tmp.m.x == tmp.l.x && tmp.m.y == tmp.l.y){
            cout << tmp.count << endl;
            q.push(tmp);
            break;
          }
          isnot_table[tmp.m.x][tmp.m.y][tmp.l.x][tmp.l.y] = false;
          q.push(tmp);
        }
      }

      if(q.empty()){
        cout << "NA" << endl;
      }

    }
    return 0;
}

Measured memory_bytes: 9668