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

const string Direction = {"ENWS"};
const int Next[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

int main() {
    int w, h;
    while(cin >> w >> h, w | h) {
        int time;
        vector<string> map(h);
        for(int i = 0; i < h; ++i) cin >> map[i];

        for(time = 0; time <= 180; ++time) {
            bool ok = true;
            for(const auto& line: map) for(const auto& c: line)
                if(Direction.find(c) != string::npos) ok = false;
            if(ok) break;
            // turn
            for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j) {
                int index = Direction.find(map[i][j]);
                if(index == string::npos) continue;
                index = (index - 1 + 4) % 4;
                for(int k = 0; k < 5; ++k) {
                    int y = i + Next[index][0];
                    int x = j + Next[index][1];
                    if(map[y][x] == '.' || map[y][x] == 'X') break;
                    index = (index + 1) % 4;
                }
                map[i][j] = Direction[index];
            }
            // move
            vector<vector<int>> used(h, vector<int>(w, 0));
            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 d = 0; d < 4; ++d) {
                    int y = i + Next[d][0];
                    int x = j + Next[d][1];
                    int index = Direction.find(map[y][x]);
                    if(index == string::npos) continue;
                    if((index - d + 4) % 4 != 2) continue;
                    if(used[y][x]) continue;
                    used[i][j] = 1;
                    if(map[i][j] == '.') swap(map[i][j], map[y][x]);
                    else map[y][x] = '.';
                    break;
                }
            }
        }

        if(time > 180) cout << "NA" << endl;
        else cout << time << endl;
    }
}