#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

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

int main()
{
	int h, w;
	while(scanf("%d%d", &w, &h), w){
		char field[32][32];
		rep(i, h){
			scanf("%s", field[i]);
		}

		int t;
		for(t=0; t<180; ++t){
			int human = 0;
			rep(i, h) rep(j, w){
				int dir = -1;
				if(field[i][j] == 'E') dir = 0;
				if(field[i][j] == 'N') dir = 1;
				if(field[i][j] == 'W') dir = 2;
				if(field[i][j] == 'S') dir = 3;

				if(dir<0)
					continue;
				++human;

				const int dd[] = {3, 0, 1, 2};
				int newdir = dir;
				rep(k, 4){
					int pd = (dir + dd[k]) % 4;
					int py = i + dy[pd];
					int px = j + dx[pd];
					if(field[py][px] == '.' || field[py][px] == 'X'){
						newdir = pd;
						break;
					}
				}
				field[i][j] = "ENWS"[newdir];
			}
			
			char next[32][32];
			rep(i, h) rep(j, w)
				next[i][j] = field[i][j];
			
			rep(i, h) rep(j, w){
				rep(k, 4){
					if(field[i][j] != '.' && field[i][j] != 'X')
						continue;
					
					int py = i + dy[k];
					int px = j + dx[k];
					if(py<0 || h<=py || px<0 || w<=px)
						continue;
					
					if(field[py][px] == "WSEN"[k]){
						if(field[i][j] == '.'){
							next[i][j] = field[py][px];
						}else
							--human;
						next[py][px] = '.';
						break;
					}
				}
			}
			if(human == 0)
				break;
			rep(i, h) rep(j, w)
				field[i][j] = next[i][j];
		}
		if(t == 180)
			puts("NA");
		else
			printf("%d\n", t+1);
	}

	return 0;
}