#include <string>
#include <vector>
#include <iostream>
using namespace std;
string ds = "ENWS";
int dx[4] = { 0, -1, 0, 1 };
int dy[4] = { 1, 0, -1, 0 };
int H, W; string s[33]; bool flag[33][33];
int main() {
	while (cin >> W >> H, H | W) {
		for (int i = 0; i < H; i++) cin >> s[i];
		int ret = -1;
		for (int i = 1; i <= 180; i++) {
			for (int j = 0; j < H; j++) {
				for (int k = 0; k < W; k++) {
					flag[j][k] = false;
					int pd = ds.find(s[j][k]);
					if (pd == string::npos) continue;
					for (int l = 3; l < 7; l++) {
						int tx = j + dx[(pd + l) % 4], ty = k + dy[(pd + l) % 4];
						if (s[tx][ty] == '.' || s[tx][ty] == 'X') {
							s[j][k] = ds[(pd + l) % 4];
							break;
						}
					}
				}
			}
			for (int j = 0; j < H; j++) {
				for (int k = 0; k < W; k++) {
					if (s[j][k] == '.' || s[j][k] == 'X') {
						for (int l = 0; l < 4; l++) {
							int tx = j + dx[l], ty = k + dy[l];
							if (0 <= tx && tx < H && 0 <= ty && ty < W) {
								int pd = ds.find(s[tx][ty]);
								if (pd == string::npos || pd != (l + 2) % 4) continue;
								flag[tx][ty] = true;
								break;
							}
						}
					}
				}
			}
			for (int j = 0; j < H; j++) {
				for (int k = 0; k < W; k++) {
					if (flag[j][k]) {
						int pd = ds.find(s[j][k]);
						int tx = j + dx[pd], ty = k + dy[pd];
						if (s[tx][ty] == '.') swap(s[j][k], s[tx][ty]);
						else s[j][k] = '.';
					}
				}
			}
			int cnt = 0;
			for (int j = 0; j < H; j++) {
				for (int k = 0; k < W; k++) {
					if (ds.find(s[j][k]) != string::npos) cnt++;
				}
			}
			if (cnt == 0) {
				ret = i;
				break;
			}
		}
		if (ret == -1) cout << "NA" << endl;
		else cout << ret << endl;
	}
	return 0;
}