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

#define REP(i,n) for(int i=0;i<(int)(n);++i)

int R, C;
string table[32];
int num[32][32];

const int dr[] = {0, -1, 0, 1};
const int dc[] = {1, 0, -1, 0};

const string aim = "ENWS";
inline int isPerson(int ch) {
  if( ch == 'E' ) return 0;
  if( ch == 'N' ) return 1;
  if( ch == 'W' ) return 2;
  if( ch == 'S' ) return 3;
  return -1;
}

int solve() {
  for(int turn = 0; turn < 180; turn++) {
    REP(i, R) REP(j, C) num[i][j] = 0;
    int o = 0;
    REP(r, R) REP(c, C) {
      if( isPerson( table[r][c] ) >= 0 ) {
        o++;
        int d = isPerson(table[r][c]);
        for(int k = 0; k < 4; k++) {
          int nr = r + dr[(k + d + 3) % 4];
          int nc = c + dc[(k + d + 3) % 4];
          if( table[nr][nc] == '.' || table[nr][nc] == 'X' ) {
            d = (k + d + 3) % 4;
            ++num[nr][nc];
            break;
          }
        }
        table[r][c] = aim[d];
      }
    }
    if( o == 0 ) return turn;

//     REP(i, R) cout << table[i] << endl;
//     cout << endl;

    REP(r, R) REP(c, C) {
      if( num[r][c] > 0 ) {
        REP(k, 4) {
          int nr = r + dr[k];
          int nc = c + dc[k];
          if( 0 <= nr && nr < R && 0 <= nc && nc < C && isPerson( table[nr][nc] ) >= 0 ) {
            if( table[r][c] == 'X' ) {
              table[nr][nc] = '.';
            } else {
              swap( table[r][c], table[nr][nc] );
            }
            break;
          }
        }
      }
    }

  }
  return -1;
}
int main() {
  for(;;) {
    cin >> C >> R; if( R == 0 && C == 0 ) break;
    REP(i, R) cin >> table[i];

    int res = solve();
    if( res == -1 ) cout << "NA" << endl;
    else cout << res << endl;
  }
  return 0;
}