function move(y,x){
   for(var i=0;i<4;i++){
      var Y=y+dy[i];
      var X=x+dx[i];
      if(Y<0 || X<0 || Y>=h || X>=w)continue;
      if(yx[Y][X]=="X"){
         yx[y][x]="g";
         sum--;
         break;
      } else if(yx[Y][X]=="."){
         yx[Y][X]=[yx[Y][X]];
         yx[y][x]=[yx[y][x],news[i]];
         break;
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var wh=arr.shift();
   if(wh=="0 0")break;
   wh=wh.split(" ").map(Number);
   var w=wh[0];
   var h=wh[1];
   var yx=[];
   for(var i=0;i<h;i++)yx.push(arr.shift().split(""));
   var sum=0;
         for(var y=0;y<h;y++){
         for(var x=0;x<w;x++){
            if(yx[y][x]=="N" || yx[y][x]=="E" || yx[y][x]=="W" || yx[y][x]=="S")sum++;
         }
         }
   var cnt=0;
   while(true){
      if(sum==0)break;
      if(cnt>180)break;
      cnt++;
      for(var y=0;y<h;y++){
         for(var x=0;x<w;x++){
            if(yx[y][x]=="N"){
               var dy=[0,-1,0,1];
               var dx=[1,0,-1,0];
               var news=["E","N","W","S"];
               move(y,x);
            }
            if(yx[y][x]=="E"){
               var dy=[1,0,-1,0];
               var dx=[0,1,0,-1];
               var news=["S","E","N","W"];
               move(y,x);
            }
            if(yx[y][x]=="W"){
               var dy=[-1,0,1,0];
               var dx=[0,-1,0,1];
               var news=["N","W","S","E"];
               move(y,x);
            }
            if(yx[y][x]=="S"){
               var dy=[0,1,0,-1];
               var dx=[-1,0,1,0];
               var news=["W","S","E","N"];
               move(y,x);
            }
         }
      }
      for(var y=0;y<h;y++){
         for(var x=0;x<w;x++){
            if(Array.isArray(yx[y][x]) && yx[y][x].length==1){
               var dy=[0,-1,0,1];
               var dx=[1,0,-1,0];
               var flag=false;
               for(var i=0;i<4;i++){
                  var Y=y+dy[i];
                  var X=x+dx[i];
                  if(Y<0 || X<0 || Y>=h || X>=w)continue;
                  if(Array.isArray(yx[Y][X]) && yx[Y][X].length==2){
                     if(flag==false){
                        yx[y][x]=yx[Y][X][1];
                         yx[Y][X]=".";
                         flag=true;
                     }else{
                        yx[Y][X]=yx[Y][X][0];
                     }
                  }
               }
            }
         }
      }
      for(var y=0;y<h;y++){
         for(var x=0;x<w;x++){
            if(yx[y][x]=="g")yx[y][x]=".";
         }
      }      
   }
   (cnt>180)?console.log("NA"):console.log(cnt);
}