#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <cstring>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int W, H;
std::string map[30];
std::vector<State> ps;
std::vector<int> rs;
int candicates[30][30];
int order[16] = {3, 0, 2, 1, 2, 1, 3, 0, 0, 2, 1, 3, 1, 3, 0, 2}, 
    order2[4] = {3, 1, 0, 2};

int directionId(char c){
    if(c == 'S'){
        return 0;
    }else if(c == 'N'){
        return 1;
    }else if(c == 'E'){
        return 2;
    }else if(c == 'W'){
        return 3;
    }
    return -1;
}

int main(){
    while(std::cin >> W >> H, W || H){
        ps.clear();

        REP(i, H){
            std::cin >> map[i];
        
            REP(j, W){
                int d;
                if((d = directionId(map[i][j])) != -1){
                    ps.push_back(mp(d, mp(j, i)));
                    map[i][j] = '#';
                }
            }
        }

        int t = 0;
        while(t <= 180 && !ps.empty()){
            memset(candicates, -1, sizeof(candicates));

            REP(i, (int)ps.size()){
                int d = ps[i].first;
                REP(j, 4){
                    int nx = ps[i].second.first + dx[order[d*4+j]],
                        ny = ps[i].second.second + dy[order[d*4+j]];

                    if(0 <= nx && nx < W &&
                       0 <= ny && ny < H && map[ny][nx] != '#'){
                        ps[i].first = order[d*4+j];
                        // printf("%d, %d, %d, %d: %d\n", i, j, nx, ny, (order[d*4+j]+2)%4);
                        if(candicates[ny][nx] == -1 || (order2[order[d*4+j]]+2) % 4 < candicates[ny][nx] % 4){
                            candicates[ny][nx] = (order2[order[d*4+j]]+2) % 4 + i * 4;
                        }
                        break;
                    }
                }
            }

            REP(i, H){
                REP(j, W){
                    // printf("%d ", candicates[i][j]);
                    if(candicates[i][j] == -1){continue;}

                    int index = candicates[i][j] / 4;
                    map[ps[index].second.second][ps[index].second.first] = '.';
                    if(map[i][j] == 'X'){
                        rs.push_back(index);
                    }else{
                        map[i][j] = '#';
                        ps[index].second = mp(j, i);
                    }
                }
                // puts("");
            }

            std::sort(rs.rbegin(), rs.rend());
            for(auto r : rs){
                ps.erase(ps.begin() + r);
            }
            rs.clear();

            // REP(i, H){
            //     REP(j, W){
            //         putchar(map[i][j]);
            //     }
            //     puts("");
            // }
            // puts("-----------------------------------------");

            t += 1;
        }

        if(t > 180){
            puts("NA");
        }else{
            printf("%d\n", t);
        }
    }

    return 0;
}

Measured memory_bytes: 1236