#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,a,b) for(int i=a;i<int(b);i++)
#define rep(i,n) REP(i,0,n)
 
int W, H;
vector<string> G;
vector<tuple<int, int, int>> Ps;// y, x, dir
 
string const DIRS = "ENWS";
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
 
bool in_range(int y, int x) {
  return 0<=y&&y<H && 0<=x&&x<W;
}
 
bool adjacent(int i, int j, int y, int x, int dir) {
  const int ny = y + dy[dir], nx = x + dx[dir];
  if(i == ny && j == nx) return true;
  return false;
}
 
int get_dir(int i, int j, int y, int x) {
  // precondition adjacent = 1;
  rep(k, 4) {
    int ni = i + dy[k], nj = j + dx[k];
    if(ni == y && nj == x) {
      return k;
    }
  }
  assert(false);
}
 
void move_person(int pid) {
  int y, x, d; tie(y, x, d) = Ps[pid];
  Ps[pid] = make_tuple(y + dy[d], x + dx[d], d);
}
 
bool is_on_exit(int pid) {
  int y, x, _; tie(y, x, _) = Ps[pid];
  if(G[y][x] == 'X') return true;
  return false;
}
 
int simulate() {
   
  int ans = 0;
   
  while(!Ps.empty() && ans <= 180) {
#if 0
    rep(i, Ps.size()) {
      cout << "pid: " << i << endl;
      int y, x, d; tie(y, x, d) = Ps[i];
      cout << "(" << y << ", " << x << ", " << d << ")" << endl;
    }
    cout << "------" << endl;
#endif
 
    set<int> pset;
    vector<pair<int, int>> V;
 
    vector<tuple<int, int, int>> nps = Ps;
     
    rep(i, Ps.size()) {
      int y, x, dir; tie(y, x, dir) = Ps[i];
      int ndir = -1;
      for(int k=dir+3; k<dir+7; k++) {
    int ny = y + dy[k%4], nx = x + dx[k%4];
    if(!in_range(ny, nx)) continue;
    if(G[ny][nx] == '#') continue;
     
    bool ng = 0;
    rep(pid, Ps.size()) {
      if(pid == i) continue;
      int yy, xx, dd; tie(yy, xx, dd) = Ps[pid];
      int ny = y + dy[k%4], nx = x + dx[k%4];
      if(yy == ny && xx == nx) ng = 1;
    }
    if(ng) continue;
     
    ndir = k%4;
    break;
      }
      if(ndir != -1) {
    nps[i] = make_tuple(y, x, ndir);
    V.emplace_back(y+dy[ndir], x+dx[ndir]);
      }
    }
     
    Ps = nps;
 
    set<int> movers;
     
    rep(ii, V.size()) {
      int i = V[ii].first, j = V[ii].second;
      vector<pair<int, int>> vs; 
      rep(pid, Ps.size()) {
    int y, x, dir; tie(y, x, dir) = Ps[pid];
    if(adjacent(i, j, y, x, dir)) {
      vs.emplace_back(get_dir(i, j, y, x), pid);
    }
      }
       
      if(!vs.empty()) {
    sort(vs.begin(), vs.end());
    int pid = vs[0].second;
    movers.insert(pid);
      }
    }
 
    for(auto && e: movers) {
      move_person(e);
    }
 
    vector<tuple<int, int, int>> NPs;
    rep(i, Ps.size()) {
      if(!is_on_exit(i)) {
    NPs.push_back(Ps[i]);
      }
    }
    Ps = NPs;
    ans ++;
  }
 
  if(ans > 180) return -1;
   
  return ans;
}
 
int main() {
   
  while(cin >> W >> H && (W | H)) {
    G.clear();
    G.resize(H);
    rep(i, H) {
      cin >> G[i];
    }
     
    Ps.clear();
     
    rep(i, H) rep(j, W) {
      if(DIRS.find(G[i][j]) != string::npos) {
    int dir = DIRS.find(G[i][j]);
    int y = i, x = j;
    Ps.emplace_back(y, x, dir);
      }
    }
     
    int r = simulate();
    if(r == -1) {
      cout << "NA" << endl;
    } else {
      cout << r << endl;
    }
  }
   
  return 0;
}

Measured memory_bytes: 3036