#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<VI> VVI;
template<class T> T gcd( T a, T b ) {
	return !b ? a : gcd( b, a % b );
}
template<class T> T lcm( T a, T b ) {
	return a / gcd( a, b ) * b;
}
template<class T> string print_v( vector<T> v ) {
	OSS oss;
	for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end();
			++it_i ) {
		oss << *it_i << ", ";
	}
	return oss.str();
}

const int dr[4] = { 0, -1, 0, 1 };
const int dc[4] = { 1, 0, -1, 0 };
const string dt = "ENWS"; // 東、北、西、南
map <char, int> ID;

int w, h;

bool is_empty_cell( const VS& M, const int r, const int c ) {
    return M[r][c] == '.' || M[r][c] == 'X';
}

bool is_obj_cell( const VS& M, const int r, const int c ) {
    return M[r][c] == '#';
}

bool is_human_cell( const VS& M, const int r, const int c ) {
    return ! is_empty_cell( M, r, c ) && M[r][c] != '#';
}

bool is_exit_cell( const VS& M, const int r, const int c ) {
    return M[r][c] == 'X';
}

void debug_print( const VS& M ) {
    static int cnt = 0;
    cout << ( ++ cnt ) << ": " << endl;
    for ( int i = 0; i < h; ++ i ) {
        for ( int j = 0; j < w; ++ j ) {
            cout << M[i][j];
        }
        cout << endl;
    }
    cout << endl;
}

VS move( VS M ) {
    // debug_print( M );
    int cnt = 0;
    for ( int i = 0; i < h; ++ i ) {
        for ( int j = 0; j < 4; ++ j ) {
            cnt += count( M[i].begin(), M[i].end(), dt[j] );
        }
    }
    // その1
    for ( int i = 0; i < h; ++ i ) {
        for ( int j = 0; j < w; ++ j ) {
            if ( ! is_human_cell( M, i, j ) ) continue;
            ([]( VS& res, int r, int c ) {
                char now = res[r][c];
                // cout << r << ", " << c << ", " << now << ", " << ID[now] << endl;
                for ( int i = 0; i < 4; ++ i ) {
                    int k = ( ID[now] + i ) % 4;
                    int nr = r + dr[k];
                    int nc = c + dc[k];
                    if ( nr < 0 || nr >= h ) continue;
                    if ( nc < 0 || nc >= w ) continue;
                    if ( is_empty_cell( res, nr, nc ) ) {
                        res[r][c] = dt[k];
                        // cout << "from: " << r << ", " << c << ", " << now << ", " << ( ID[now] + i ) % 4;
                        // cout << " => " << nr << ", " << nc << ", " << dt[k] << ", " << k << endl;
                        return;
                    }
                }
            })( M, i, j );
        }
    }
    // その2
    VS res = M;
    for ( int i = 0; i < h; ++ i ) {
        for ( int j = 0; j < w; ++ j ) {
            if ( ! is_empty_cell( res, i, j ) ) continue;
            ([]( VS& M, VS& res, int r, int c ) {
                for ( int i = 0; i < 4; ++ i ) {
                    int nr = r + dr[i];
                    int nc = c + dc[i];
                    if ( nr < 0 || nr >= h ) continue;
                    if ( nc < 0 || nc >= w ) continue;
                    int adj = ( i + 2 ) % 4;
                    if ( M[nr][nc] == dt[adj] ) {
                        if ( ! is_exit_cell( M, r, c ) )
                            res[r][c] = M[nr][nc];
                        res[nr][nc] = '.';
                        M[nr][nc] = '#';
                        return;
                    }
                }
            })( M, res, i, j );
        }
    }
    // debug_print( res );
    // cout << cnt << endl;
    return res;
}

bool is_empty_field( VS& M ) {
    for ( int i = 0; i < h; ++ i ) {
        for ( int j = 0; j < w; ++ j ) {
            if ( is_human_cell( M, i, j ) ) return false;
        }
    }
    return true;
}

int solve( VS M ) {
    if ( is_empty_field( M ) )
        return 0;
    for ( int i = 1; i <= 180; ++ i ) {
        M = move( M );
        if ( is_empty_field( M ) )
            return i;
    }
    return -1;
}

void init_ID() {
    ID.clear();
    ID['E'] = 3;
    ID['N'] = 0;
    ID['W'] = 1;
    ID['S'] = 2;
}

int main() {
    init_ID();
    
    while ( cin >> w >> h && w ) {
        // cout << "test: " << w << ", " << h << endl;
        VS lines(h);
        for ( int i = 0; i < h; ++ i ) cin >> lines[i];
        int ret = solve( lines );
        if ( ret == -1 )
            cout << "NA" << endl;
        else
            cout << ret << endl;
    }
	return 0;
}