#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

//right+1,front+0,left+3,back+2
enum{NORTH,EAST,SOUTH,WEST};
const int dir[4]={1,0,3,2};
const int dx[]={0,1,0,-1};
const int dy[]={-1,0,1,0};

const int gdir[]={WEST,SOUTH,EAST,NORTH};
const int gx[]  ={1,0,-1,0};
const int gy[]  ={0,-1,0,1};


const int N = 100;
char inp[N][N];
//-1 daremo inai
int m[N][N];//-1,  dir 0,1,2,3 
int mnext[N][N];

void output(int r,int c){
  rep(i,r){
    rep(j,c){
      cout << m[i][j]<<" " ;
    }
    cout << endl;
  }
  cout << endl;
}

void solve(int r,int c){
  rep(loop,181){
    rep(i,r)rep(j,c)if (m[i][j] != -1)goto end;
    cout << loop << endl;
    return;
  end:;

    //change dir
    rep(i,r){
      rep(j,c){
	if (m[i][j] == -1)continue;
	rep(k,4){
	  int next = (m[i][j] + dir[k])%4;
	  int nex = j+dx[next],ney=i+dy[next];
	  if (nex == -1 || ney == -1 || nex == c || ney == r)continue;
	  if (inp[ney][nex] != '#' && m[ney][nex] == -1){
	    m[i][j] = next;
	    break;
	  }
	}
      }
    }

    rep(i,r)rep(j,c)mnext[i][j] = m[i][j];
    //move
    rep(i,r){
      rep(j,c){
	if (inp[i][j] == '#' || m[i][j] != -1)continue;
	rep(k,4){
	  int ney = i+gy[k],nex=j+gx[k];
	  if (nex == -1 || ney == -1 || nex == c || ney == r)continue;
	  //cout << i <<" " << j <<" " << ney <<" " << nex <<" " << m[ney][nex] << " " << k << " " << gdir[k] << endl;
	  if (m[ney][nex] == gdir[k]){
	    swap(mnext[i][j],mnext[ney][nex]);
	    break;
	  }
	}
      }
    }

    rep(i,r)rep(j,c)m[i][j] = mnext[i][j];
    //output(r,c);
    rep(i,r)rep(j,c)if (inp[i][j] == 'X' && m[i][j] != -1)m[i][j] = -1;
  }
  cout << "NA" << endl;
}

main(){
  int c,r;
  while(cin>>c>>r && c){
    rep(i,r)cin>>inp[i];
    rep(i,r){
      rep(j,c){
	if (inp[i][j] == '.' || inp[i][j] == '#' || inp[i][j] == 'X'){
	  m[i][j] = -1;
	}else if (inp[i][j] == 'E'){
	  inp[i][j] = '.';
	  m[i][j] = 1;
	}else if (inp[i][j] == 'S'){
	  inp[i][j] = '.';
	  m[i][j] = 2;
	}else if (inp[i][j] == 'W'){
	  inp[i][j] = '.';
	  m[i][j] = 3;
	}else if (inp[i][j] == 'N'){
	  inp[i][j] = '.';
	  m[i][j] = 0;
	}
      }
    }
    solve(r,c);
  }
}