#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

int w, h;
char s[30][31], b[30][31];
map<char, int>d{ {'N',0},{'E',1},{'S',2},{'W',3} };
char rd[] = "NESW";
int dx[]{ -1,0,1,0 }, dy[]{ 0,1,0,-1 }, a[]{ 1,0,3,2 };
int main() {
	while (scanf("%d%d", &w, &h), h) {
		rep(i, h)scanf("%s", s[i]);
		for (int i = 0; i <= 180; i++) {
			bool ok = true;
			rep(i, h)rep(j, w)for (auto p : d) {
				if (s[i][j] == p.first) { ok = false; break; }
			}
			if (ok) { printf("%d\n", i); goto g; }
			rep(i, h)rep(j, w) {
				if (d.find(s[i][j]) == d.end())continue;
				int b = d[s[i][j]];
				rep(k, 4) {
					int nx = i + dx[(b + a[k]) % 4], ny = j + dy[(b + a[k]) % 4];
					if (0 <= nx&&nx < h && 0 <= ny&&ny < w && (s[nx][ny] == '.' || s[nx][ny] == 'X')) {
						s[i][j] = rd[(b + a[k]) % 4]; break;
					}
				}
			}
			rep(i, h)rep(j, w)b[i][j] = s[i][j];
			rep(i, h)rep(j, w) {
				if (s[i][j] != 'X'&&s[i][j] != '.')continue;
				rep(k, 4) {
					int nx = i + dx[a[k]], ny = j + dy[a[k]];
					if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&d.find(s[nx][ny]) != d.end() && nx + dx[d[s[nx][ny]]] == i&&ny + dy[d[s[nx][ny]]] == j) {
						if (s[i][j] == 'X')b[nx][ny] = '.';
						else swap(b[i][j], b[nx][ny]);
						break;
					}
				}
			}
			rep(i, h)rep(j, w)s[i][j] = b[i][j];
		}
		puts("NA");
	g:;
	}
}