#include <iostream>
#include <string>
#include <vector>
#include <cctype>

using namespace std;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int main(){
	while(true){
		int W, H;
		cin >> W >> H;
		if(W == 0 && H == 0){ break; }
		vector<string> field;
		field.push_back(string(W + 2, '#'));
		for(int i = 0; i < H; ++i){
			string line;
			cin >> line;
			field.push_back("#" + line + "#");
		}
		field.push_back(string(W + 2, '#'));
		W += 2; H += 2;
		for(int i = 0; i < H; ++i){
			for(int j = 0; j < W; ++j){
				switch(field[i][j]){
				case 'N': field[i][j] = '0'; break;
				case 'E': field[i][j] = '1'; break;
				case 'S': field[i][j] = '2'; break;
				case 'W': field[i][j] = '3'; break;
				}
			}
		}
		int answer = 0;
		while(answer <= 180){
			bool goal = true;
			for(int i = 0; i < H; ++i){
				for(int j = 0; j < W; ++j){
					if(isdigit(field[i][j])){ goal = false; }
				}
			}
			if(goal){ break; }
			++answer;
			for(int i = 0; i < H; ++i){
				for(int j = 0; j < W; ++j){
					if(!isdigit(field[i][j])){ continue; }
					int next = field[i][j] - '0', offset = 'a';
					for(int k = 5; k >= 0; --k){
						next = (field[i][j] - '0' + k) % 4;
						if(field[i + dy[next]][j + dx[next]] == '.'){ offset = '0'; break; }
						if(field[i + dy[next]][j + dx[next]] == 'X'){ offset = '0'; break; }
					}
					field[i][j] = next + offset;
				}
			}
			for(int i = 0; i < H; ++i){
				for(int j = 0; j < W; ++j){
					int c = field[i][j];
					if(c != '.' && c != 'X'){ continue; }
					for(int k = 5; k > 1; --k){
						int x = j + dx[k % 4], y = i + dy[k % 4];
						if(isdigit(field[y][x])){
							int px = x + dx[field[y][x] - '0'], py = y + dy[field[y][x] - '0'];
							if(px != j || py != i){ continue; }
							field[i][j] = c == 'X' ? '*' : field[y][x] - '0' + 'a';
							field[y][x] = '@';
							break;
						}
					}
				}
			}
			for(int i = 0; i < H; ++i){
				for(int j = 0; j < W; ++j){
					int c = field[i][j];
					if(islower(c)){ field[i][j] = c - 'a' + '0'; }
					if(c == '@'){ field[i][j] = '.'; }
					if(c == '*'){ field[i][j] = 'X'; }
				}
			}
		}
		if(answer > 180){
			cout << "NA" << endl;
		}else{
			cout << answer << endl;
		}
	}
	return 0;
}