#include <bits/stdc++.h>
using namespace std;

const int dy[4] = {1, 0, -1, 0};
const int dx[4] = {0, 1, 0, -1};
const string ENWS = "ENWS";

int main() {
    int W, H;
    while (cin >> W >> H, W) {
        vector<string> S(H);
        for (int i = 0; i < H; ++i) cin >> S[i];

        int ans = -1;
        for (int t = 0; t <= 180; ++t) {
            vector<pair<int, int>> pos;
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    if (ENWS.find(S[i][j]) != string::npos) {
                        pos.emplace_back(i, j);
                    }
                }
            }
            if (pos.empty()) {
                ans = t;
                break;
            }

            map<pair<int, int>, vector<pair<int, int>>> mp;
            for (int i = 0; i < pos.size(); ++i) {
                int y, x;
                tie(y, x) = pos[i];
                int dir = ENWS.find(S[y][x]);
                for (int j = 0; j < 4; ++j) {
                    int ny = y + dy[(dir + j) % 4];
                    int nx = x + dx[(dir + j) % 4];
                    if (ny >= 0 && ny < H && nx >= 0 && nx < W && (S[ny][nx] == '.' || S[ny][nx] == 'X')) {
                        mp[make_pair(ny, nx)].emplace_back((dir + j + 1) % 4, i);
                        S[y][x] = ENWS[(dir + j + 3) % 4];
                        break;
                    }
                }
            }
            for (auto &p : mp) {
                sort(p.second.begin(), p.second.end());
                int sy, sx, ty, tx;
                tie(sy, sx) = pos[p.second[0].second];
                tie(ty, tx) = p.first;
                if (S[ty][tx] == '.') {
                    S[ty][tx] = S[sy][sx];
                }
                S[sy][sx] = '.';
            }
        }
        if (ans < 0) cout << "NA" << endl;
        else cout << ans << endl;
    }
}

