#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>

using namespace std;

typedef complex<int> P;

struct human {
	P p;
	int dir;

	human(P p, int dir) : p(p), dir(dir) { }
	human() { this -> p = P(0, 0); this -> dir = 0; }
};

bool cp(human a, human b) {
	return a.dir > b.dir;
}

int abs(int n) {
	return n < 0 ? -n : n;
}

P dir(int n) {
	n %= 4;
	return n == 0 ? P(0, -1) : n == 1 ? P(1, 0) : n == 2 ? P(0, 1) : P(-1, 0);
}

int W, H;
int m[30][30];
int state(P p) {
//	if (p.real() < 0 || p.real() >= W || p.imag() < 0 || p.imag() >= H) cout << "ERROR" << endl;
//	cout << p.real() << " " << p.imag() << endl;
	return m[p.imag()][p.real()];
}

int main() {
	while (cin >> W >> H, W || H) {
		vector<human> v;

		for (int y = 0; y < H; ++y) {
			string str; cin >> str;
			for (int x = 0; x < W; ++x)
				m[y][x] =
					  str[x] == '#' ? 1
					: str[x] == 'X' ? -1
					: str[x] == 'N' ? (v.push_back( human( P(x, y), 0) ), 2)
					: str[x] == 'E' ? (v.push_back( human( P(x, y), 1) ), 2)
					: str[x] == 'S' ? (v.push_back( human( P(x, y), 2) ), 2)
					: str[x] == 'W' ? (v.push_back( human( P(x, y), 3) ), 2)
					: 0
					;
		}

		int t = 0;
		while (v.size() && ++t < 180) {
			// 向き変更
			for (int i = 0; i < v.size(); ++i)
				v[i].dir =
					  state(v[i].p + dir(v[i].dir + 1)) <= 0 ? (v[i].dir + 1) % 4
					: state(v[i].p + dir(v[i].dir))     <= 0 ? v[i].dir
					: state(v[i].p + dir(v[i].dir + 3)) <= 0 ? (v[i].dir + 3) % 4
					: state(v[i].p + dir(v[i].dir + 2)) <= 0 ? (v[i].dir + 2) % 4
					: v[i].dir
					;

			// 向きでソート
			sort( v.begin(), v.end(), cp );

			// 移動
			for (int i = 0; i < v.size(); ++i) {
				int s = state(v[i].p + dir(v[i].dir));
				if (s > 0) continue;

				m[v[i].p.imag()][v[i].p.real()] = 0;
				v[i].p += dir(v[i].dir);

				if (s == 0) m[v[i].p.imag()][v[i].p.real()] = 2;
				else v.erase( v.begin() + i-- );
			}
		}

		if (t >= 180) cout << "NA" << endl;
		else cout << t << endl;
	}
}