#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

int w, h;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
bool flg[32][32];
char t[32][32];

int main(){
  while(cin >> w >> h, w || h){
    int rem = 0;

    for(int i = 0; i < h; i++){
      cin >> t[i];
      for(int j = 0; j < w; j++){
        if(t[i][j] == 'E') { t[i][j] = 0; rem++; }
        if(t[i][j] == 'N') { t[i][j] = 1; rem++; }
        if(t[i][j] == 'W') { t[i][j] = 2; rem++; }
        if(t[i][j] == 'S') { t[i][j] = 3; rem++; }
      }
    }

    int i;
    int ans = -1;

    for(i = 0; rem != 0 && i <= 180; i++){
      for(int x = 0; x < w; x++){
        for(int y = 0; y < h; y++){
          if(t[y][x] < 4){
            for(int j = 0; j < 4; j++){
              int nd = (t[y][x] + j + 3) % 4;
              int nx = x + dx[nd];
              int ny = y + dy[nd];

              if(4 <= t[ny][nx] && (t[ny][nx] == '.' || t[ny][nx] == 'X')){
                t[y][x] = nd;
                break;
              }
            }
          }
        }
      }

      memset(flg, 0, sizeof(flg));

      for(int x = 0; x < w; x++){
        for(int y = 0; y < h; y++){
          if(t[y][x] == '.' || t[y][x] == 'X'){
            for(int j = 0; j < 4; j++){
              int nx = x + dx[j];
              int ny = y + dy[j];

              if(0 <= nx && nx < w && 0 <= ny && ny < h && t[ny][nx] == (j + 2) % 4 && !flg[ny][nx]){
                flg[ny][nx] = true;
                break;
              }
            }
          }
        }
      }

      for(int x = 0; x < w; x++){
        for(int y = 0; y < h; y++){
          if(flg[y][x]){
            int d = t[y][x];
            int nx = x + dx[d];
            int ny = y + dy[d];

            if(t[ny][nx] == 'X'){
              rem--;
            }
            else{
              t[ny][nx] = d;
            }
            t[y][x] = '.';
          }
        }
      }
    }

    if(i <= 180){
      cout << i << endl;
    }
    else{
      cout << "NA\n";
    }
  }
}