#include <iostream>
#include <cstdlib>

using namespace std;

const int N = 30;

int h, w, p;
char mapData[N][N];
bool used[N][N];
int dy[] = {0, -1, 0, 1};
int dx[] = {1, 0, -1, 0};

int convertDirection(char c){
   if(c == 'E') return 0;
   if(c == 'N') return 1;
   if(c == 'W') return 2;
   if(c == 'S') return 3;
}

char convertInteger(int d){
   if(d == 0) return 'E';
   if(d == 1) return 'N';
   if(d == 2) return 'W';
   if(d == 3) return 'S';
}

void changeDirection(int y, int x, char c){
   for(int i=0;i<4;++i){
      int d = (convertDirection(c)+3+i)%4;
      int ty = y + dy[d];
      int tx = x + dx[d];
      if(!(mapData[ty][tx] == '.' || mapData[ty][tx] == 'X')) continue;
      mapData[y][x] = convertInteger(d);
      return;
   }
}

void searchPerson(){
   for(int i=0;i<h;++i){
      for(int j=0;j<w;++j){
         if(mapData[i][j] == 'E' || 
            mapData[i][j] == 'N' || 
            mapData[i][j] == 'W' ||
            mapData[i][j] == 'S')
            changeDirection(i, j, mapData[i][j]);
      }
   }
}

void movePerson(int y, int x){
   int d = convertDirection(mapData[y][x]);
   int ty = y + dy[d];
   int tx = x + dx[d];
   if(mapData[ty][tx] == 'X'){
      --p;
   }else{
      mapData[ty][tx] = mapData[y][x];
   }
   mapData[y][x] = '.';
}

void selectPerson(int y, int x){
   for(int i=0;i<4;++i){
      int ty = y + dy[i];
      int tx = x + dx[i];
      if(mapData[ty][tx] == '#' || mapData[ty][tx] == '.' || mapData[ty][tx] == 'X') continue;
      if(used[ty][tx]) continue;
      if(abs(i-convertDirection(mapData[ty][tx])) == 2){
         movePerson(ty, tx);
         used[y][x] = used[ty][tx] = true;
         break;
      }
   }
}

void searchPoint(){
   for(int i=0;i<h;++i){
      for(int j=0;j<w;++j){
         if(!(mapData[i][j] == '.' || mapData[i][j] == 'X')) continue;
         selectPerson(i, j);
      }
   }
}

main(){
   while(cin >> w >> h && (h || w)){
      p = 0;
      for(int i=0;i<h;++i){
         for(int j=0;j<w;++j){
            cin >> mapData[i][j];
            if(mapData[i][j] == 'E' || 
               mapData[i][j] == 'N' || 
               mapData[i][j] == 'W' ||
               mapData[i][j] == 'S')
               ++p;
         }
      }
      if(p == 0){
         cout << 0 << endl;
         continue;
      }
      for(int t=1;;++t){
         if(t > 180){
            cout << "NA" << endl;
            break;
         }
         fill(used[0], used[N], false);
         searchPerson();
         searchPoint();
         if(p == 0){
            cout << t << endl;
            break;
         }
      }
   }
   return 0;
}