#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
// E, N, W, S
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
string ENWS = "ENWS";

int main(){
  int W, H;
  while(cin >> W >> H && W){
    vector<string> grid(H);
    REP(y, H) cin >> grid[y];
    REP(y, H) REP(x, W) if(grid[y][x] == 'X') grid[y][x] = '%';
    int rest = 0;
    REP(y, H) REP(x, W) if(isupper(grid[y][x])) rest++;
    int ans = INF;
    REP(time, 181){
      if(rest == 0) {
        ans = time;
        break;
      }
      REP(y, H) REP(x, W){
        REP(i, 4) if(grid[y][x] == ENWS[i]){
          REP(r, 4){
            int rr = (i + r + 3) % 4;
            int nx = x + dx[rr];
            int ny = y + dy[rr];
            if(valid(nx, ny, W, H) && (grid[ny][nx] == '.' || grid[ny][nx] == '%')){
              grid[y][x] = ENWS[rr];
              goto LOOPOUT;
            }
          }
        }
        LOOPOUT:;
      }
      vector<string> next = grid;
      REP(y, H) REP(x, W) if(grid[y][x] == '.' || grid[y][x] == '%') REP(r, 4){
        int nx = x + dx[r];
        int ny = y + dy[r];
        if(valid(nx, ny, W, H) && grid[ny][nx] == ENWS[(r + 2) % 4]){
          next[ny][nx] = '.';
          if(grid[y][x] == '.') next[y][x] = grid[ny][nx];
          else rest--;

          break;
        }
      }
      grid = next;
    }
    if(ans == INF) cout << "NA" << endl;
    else cout << ans << endl;
  }
  return 0;
}