#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

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

struct hero{
	int x,y,d;
	hero(){}
	hero(int a,int b,int c){ x = a , y = b , d = c;}
};
bool operator == (const hero a,const hero b){
	return a.d == b.d && a.x == b.x && a.y == b.y;
}
int H,W;
char data[30][30];
vector<hero> h;

int exists(int x,int y){
	if(data[y][x] == '#') return true;
	rep(i,h.size()) if(h[i].x == x && h[i].y == y) return true;
	return false;
}

int isok(int d,int x,int y){
	rep(i,h.size()){
		if(h[i].x == x && h[i].y == y && h[i].d == d){
			return i;
		}
	}
	return -1;
}
int wmove(hero he){
	rep(I,4){
		int i = (he.d + I) % 4;
		if( !exists(he.x+dx[i] , he.y + dy[i]) ) return (i+3) %4;
	}
	return he.d;
}

int check(int x,int y){
	return x < 0 || y < 0 || x >= W || y >= H;
}

int main(){
	while(cin >> W >> H , H || W){
		h.clear();
		rep(i,H)rep(j,W){
			hero tmp;
			char c; cin >> c;
			if(c == 'N' || c == 'W' || c == 'S' || c == 'E'){
				if(c=='N') tmp.d = 0;
				if(c=='W')tmp.d = 1;
				if(c=='S')tmp.d = 2;
				if(c=='E')tmp.d = 3;
				tmp.x = j , tmp.y = i;
				h.push_back(tmp);
			}
			data[i][j] = c;

		}
		rep(T,181){
			//cout << h[0].x << " " << h[0].y << " " << h[0].d << " " << endl;
			if(h.size() == 0){ cout << T << endl; goto exit;}
			rep(i,h.size()) h[i].d = wmove(h[i]);
			vector<hero> next = h;
			//rep(i,h.size()) cout << i << ":" << h[i].x <<"," << h[i].y << "=" << h[i].d << endl;
			rep(i,H)rep(j,W){
				rep(d,4){
					if(data[i][j] == '#' || check(j+dx[d],i+dy[d])) continue;
					int r = isok( (d+1)%4 , j+dx[d] , i+dy[d] );
					//if(i == 1 && j == 2) cout << r << "=" << (d+3)%4 << endl;
					if(~r){
						next[r].x = j ;
						next[r].y = i ;
						break;
					}
				}
			}
			rep(i,next.size()){
				if(data[next[i].y][next[i].x] == 'X'){
					next[i] = hero(-1,-1,-1);
				}
			}
			next.erase(remove(next.begin(),next.end(),hero(-1,-1,-1)),next.end());
			h = next;
		}
		cout << "NA" << endl;
		exit:;
	}
}