#include <iostream>
#include <vector>

using namespace std;

const int size = 31;

char map[size][size];
char map2[size][size];

struct Peep {
  int dir;
  int x;
  int y;
  Peep(int dir, int x, int y) : dir(dir), x(x), y(y) {}
};

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int getDir(char c) {
  return c == 'N' ? 1
      : c == 'E' ? 0
      : c == 'W' ? 2
      : c == 'S' ? 3
      : -1;
}
char dirs[] = {'E', 'N', 'W', 'S'};

int main()
{
  int w, h;
  while(cin >> w >> h, w || h) {
    vector<Peep> peeps;
    int numPeeps = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        char c;
        cin >> c;
        int dir = getDir(c);
        if(dir != -1) {
          peeps.push_back(Peep(dir, j, i));
          numPeeps++;
        }
        map[i][j] = c;
      }
    }
    int t;
    for (t = 0; t <= 180 && numPeeps > 0; t++) {
      for (int i = 1; i < h-1; i++) {
        for (int j = 1; j < w-1; j++) {
          int dir = getDir(map[i][j]);
          if (dir != -1) {
            for (int k = 0; k < 4; k++) {
              int nextX = j + dx[(dir+k+3)%4];
              int nextY = i + dy[(dir+k+3)%4];
              char nextC = map[nextY][nextX];
              if(nextC == '.' || nextC == 'X') {
                map[i][j] = dirs[(dir+k+3)%4];
//                cout << "acc:" << nextX << ", "<< nextY << ", " << map[i][j]<<endl;
                break;
              }
              else {
//                cout << "neg:" << nextX << ", "<< nextY << ", " << dirs[(dir+k+3)%4]<<endl;
              }
            }
          }
        }
      }
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          map2[i][j] = map[i][j];
        }
      }

      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (map[i][j] != '.' && map[i][j] != 'X') continue;
          for (int k = 0; k < 4; k++) {
            int neibX = j + dx[k];
            int neibY = i + dy[k];
            if (neibX < 0 || w <= neibX || neibY < 0 || h <= neibY) continue;
            char neibC = map[neibY][neibX];
            int dir = getDir(neibC);
            if (dir == (k+2)%4) {
              if (map[i][j] == 'X') {
                map2[neibY][neibX] = '.';
                numPeeps--;
              }
              else {
                map2[i][j] = dirs[dir];
                map2[neibY][neibX] = '.';
              }
              break;
            }
          }
        }
      }
/*      for (int i = 0; i < h; i++) {
        cout << "bf:" << map[i] << endl;
      }
*/      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          map[i][j] = map2[i][j];
        }
//        cout << "af:" << map[i] << endl;
      }
//      cout << endl;
    }
    if (t <= 180) cout << t << endl;
    else cout << "NA" << endl;

  }
  return 0;
}