function bomb(t,k){
   var dy=[-1,0,0,1];
   var dx=[0,-1,1,0];
   var ary=[[t,k,0]];
   var good=false;
   var obj={};
   while(true){
      if(ary.length==0)break;
      var v=ary.shift();
      var t=v[0];
      var k=v[1];
      if(obj.hasOwnProperty(t.join(",")+"&"+k.join(",")))continue;
      else obj[t.join(",")+"&"+k.join(",")]=true;
      var cnt=v[2];
      if(cnt==100)break;
      if(t[0]==k[0] && t[1]==k[1]){good=true;break;}
      for(var i=0;i<4;i++){
         var tx=t[0]+dx[i];
         var ty=t[1]+dy[i];
         var kx=k[0]+(-1*dx[i]);
         var ky=k[1]+(-1*dy[i]);
         if(tx<0 || ty<0 || tx>=x || ty>=y || yx[ty][tx]==1){
            tx=t[0];
            ty=t[1];
         }
         if(kx<0 || ky<0 || kx>=x || ky>=y || yx[ky][kx]==1){
            kx=k[0];
            ky=k[1];
         }
         ary.push([[tx,ty],[kx,ky],cnt+1]);
      }
   }
   return (good)?cnt:"NA";
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var xy=arr.shift().split(" ").map(Number);
   var x=xy[0];
   var y=xy[1];
   if(xy.join(" ")=="0 0")break;
   var t=arr.shift().split(" ").map(Number);
   t=[t[0]-1,t[1]-1];
   var k=arr.shift().split(" ").map(Number);
   k=[k[0]-1,k[1]-1];
   var yx=[];
   for(var i=0;i<y;i++)yx.push(arr.shift().split(" ").map(Number));
   console.log(bomb(t,k));
}