#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

void solve(int h, int w){

    vector<string> G(h);
    vector<vector<char>> out(h, vector<char>(w, 0));
    array<int, 4> dy{0, 1, 0, -1}, dx{-1, 0, 1, 0};
    string D = "WSEN";
    for (int i = 0; i < h; ++i) {
        cin >> G[i];
    }
    for (int t = 0; t <= 180; ++t) {
        int cnt = 0;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                for (int k = 0; k < 4; ++k) {
                    if(G[i][j] == D[k]) cnt++;
                }
            }
        }
        if(!cnt){
            cout << t << "\n";
            return;
        }
        for (int y = 0; y < h; ++y) {
            for (int x = 0; x < w; ++x) {
                for (int i = 0; i < 4; ++i) {
                    if(G[y][x] == D[i]){
                        for (int j = 3; j < 7; ++j) {

                            int dir = (i+j)&3;
                            if(G[y+dy[dir]][x+dx[dir]] == '.' || G[y+dy[dir]][x+dx[dir]] == 'X'){
                                G[y][x] = D[dir];
                                i = 10;
                                break;
                            }
                        }
                    }
                }
            }
        }
        for (int dir = 0; dir < 4; ++dir) {
            for (int y = 0; y < h; ++y) {
                 for (int x = 0; x < w; ++x) {
                    if(G[y][x] == D[dir]){
                        if(G[y+dy[dir]][x+dx[dir]] == '.'){
                            G[y+dy[dir]][x+dx[dir]] = G[y][x]-'A'+'a';
                            G[y][x] = '|';
                        }else if(G[y+dy[dir]][x+dx[dir]] == 'X'){
                            G[y][x] = '|';
                            G[y+dy[dir]][x+dx[dir]] = '$';
                        }
                    }
                }
            }
        }
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if(islower(G[i][j])){
                    G[i][j] = G[i][j]-'a'+'A';
                }else if(G[i][j] == '$'){
                    G[i][j] = 'X';
                }else if(G[i][j] == '|'){
                    G[i][j] = '.';
                }
            }
        }

    }
    puts("NA");
}

int main() {
    int w, h;
    while(cin >> w >> h, h){
        solve(h, w);
    }
    return 0;
}

