#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;


int main()
{
    int dir[256];
    dir['E'] = 0;
    dir['N'] = 1;
    dir['W'] = 2;
    dir['S'] = 3;

    int dy[] = {0, -1, 0, 1};
    int dx[] = {1, 0, -1, 0};

    int nextDir[] = {3, 0, 1, 2};

    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            return 0;

        vector<string> s(h);
        for(int i=0; i<h; ++i)
            cin >> s[i];

        int n = 0;
        vector<int> y, x, d;
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                if('E' <= s[i][j] && s[i][j] <= 'W'){
                    y.push_back(i);
                    x.push_back(j);
                    d.push_back(dir[s[i][j]]);
                    ++ n;
                    s[i][j] = '!';
                }
            }
        }

        int m = n;
        for(int t=1; t<=180; ++t){
            vector<bool> move(n, false);
            for(int i=0; i<n; ++i){
                if(s[y[i]][x[i]] == 'X')
                    continue;
                for(int j=0; j<4; ++j){
                    int d1 = (d[i] + nextDir[j]) % 4;
                    int y1 = y[i] + dy[d1];
                    int x1 = x[i] + dx[d1];
                    if(s[y1][x1] == '.' || s[y1][x1] == 'X'){
                        d[i] = d1;
                        move[i] = true;
                        break;
                    }
                }
            }

            for(int i=0; i<4; ++i){
                for(int j=0; j<n; ++j){
                    if(!move[j] || d[j] != (i+2)%4)
                        continue;
                    int y1 = y[j] + dy[d[j]];
                    int x1 = x[j] + dx[d[j]];
                    if(s[y1][x1] == '.' || s[y1][x1] == 'X'){
                        s[y[j]][x[j]] = '.';
                        if(s[y1][x1] == 'X'){
                            -- m;
                        }else{
                            s[y1][x1] = '!';
                        }
                        y[j] = y1;
                        x[j] = x1;
                    }
                }
            }
            if(m == 0){
                cout << t << endl;
                break;
            }
        }

        if(m != 0)
            cout << "NA" << endl;
    }
}