#include <bits/stdc++.h>
using namespace std;
enum {W, S, E, N};
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};
struct P {
	int x, y, ang;
	P(){}
	P(int x, int y, int ang) : x(x), y(y), ang(ang) {}
	bool operator < (const P &t) const {
		return ang < t.ang;
	}
};

int n, m;
bool grid[32][32];
bool pre[32][32];
bool goal[32][32];
vector<P> ps;

void solve()
{
	int res = 0;
	while (ps.size()){
		if (++res > 180){
			puts("NA");
			return;
		}
		
		for (int i = 0; i < ps.size(); i++){
			//printf("%d %d %d\n", i, ps[i].x, ps[i].y);
			
			for (int t = -1; t < 3; t++){
				int dir = (ps[i].ang + t + 4) % 4;
				int nx = ps[i].x + dx[dir];
				int ny = ps[i].y + dy[dir];
				if (!grid[nx][ny]){
					ps[i].ang = dir;
					break;
				}
			}
		}
		sort(ps.begin(), ps.end());
		for (int i = 0; i < ps.size(); i++){
			int nx = ps[i].x + dx[ps[i].ang];
			int ny = ps[i].y + dy[ps[i].ang];
			if (grid[nx][ny]) continue;
			pre[ps[i].x][ps[i].y] = true;
			grid[nx][ny] = true;
			ps[i].x = nx;
			ps[i].y = ny;
			if (goal[nx][ny]){
				ps.erase(ps.begin() + i--);
			}
		}
		for (int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				if (pre[i][j]) grid[i][j] = false;
				if (goal[i][j]) grid[i][j] = false;
				pre[i][j] = false;
				
				//printf("%c", grid[i][j] ? '#' : ' ');
			}
			//puts("");
		}
	}
	printf("%d\n", res);
}

int main()
{
	while (scanf("%d %d", &m, &n), m){
		memset(grid, true, sizeof(grid));
		memset(goal, false, sizeof(goal));
		ps.clear();
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m; j++){
				char c;
				scanf(" %c", &c);
				if (c == '#'){
					grid[i][j] = true;
					continue;
				}
				else if (c == 'X'){
					goal[i][j] = true;
				}
				else if (c == 'W'){
					grid[i][j] = true;
					ps.push_back(P(i, j, W));
				}
				else if (c == 'S'){
					grid[i][j] = true;
					ps.push_back(P(i, j, S));
				}
				else if (c == 'E'){
					grid[i][j] = true;
					ps.push_back(P(i, j, E));
				}
				else if (c == 'N'){
					grid[i][j] = true;
					ps.push_back(P(i, j, N));
				}
				else {
					grid[i][j] = false;
				}
			}
		}
		solve();
	}
}