#include <iostream>
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};
string dd = "ENWS";
int main(){
	int H,W;
	while(cin >> W >> H && W){
		char c[31][31]={},C[31][31]={};
		for(int i = 0 ; i < H ; i++)
			for(int j = 0 ; j < W ; j++)
				cin >> c[i][j];
		int sec = 0 , ok = 0;
		while(sec <= 180){
			int endok = 1;
			rep(i,H)rep(j,W) if(c[i][j] == 'E' || c[i][j] == 'S' || c[i][j] == 'W' || c[i][j] == 'N') endok = 0;
			if(endok){
				cout << sec << endl;
				ok = true;
				break;
			}
			pair<int,int> next[31][31];
			int done[31][31] = {};
			
			rep(i,31)rep(j,31) next[i][j] = make_pair(-1,-1);
			rep(i,H)rep(j,W) C[i][j] = c[i][j];
			rep(i,31)rep(j,31) if(C[i][j] == 'E' || C[i][j] == 'S' || C[i][j] == 'W' || C[i][j] == 'N') C[i][j] = '.';
			
			rep(i,H)rep(j,W) {
				if(c[i][j] == 'E' || c[i][j] == 'S' || c[i][j] == 'W' || c[i][j] == 'N'){
					int b = (dd.find(c[i][j]) + 3)%4;
					int f = 1;
					rep(d,4){
						int nx = j + dx[(b+d)%4];
						int ny = i + dy[(b+d)%4];
						if(c[ny][nx] == '.' || c[ny][nx] == 'X'){
							next[i][j]= make_pair(nx,ny);
							f = 0;
							break;
						}
					}
					if( f) C[i][j] = c[i][j];
				}
			}
			rep(i,H)rep(j,W) {
				if( c[i][j] == '.' || c[i][j] == 'X'){
					rep(d,4){
						int nx = j + dx[d];
						int ny = i + dy[d];
						if( (c[ny][nx] == 'E' || c[ny][nx] == 'S' || c[ny][nx] == 'W' || c[ny][nx] == 'N') && next[ny][nx] == make_pair(j,i)){
							if(done[i][j]){
								C[ny][nx] = dd[(d + 2)%4]; 
							}else{
								if( c[i][j] == '.' ) {
									//if( sec < 10 ) cout << c[ny][nx] << " " << endl;
									C[i][j] = dd[(d + 2)%4]; 
									done[i][j] = true;
								}else{
									done[i][j] = true;
								}
							}
						}
					}
				}
			}
			//if(sec < 10){ rep(i,H) cout << C[i] << endl;cout << endl;}
			rep(i,H)rep(j,W) c[i][j] = C[i][j];
			sec++;
		}
		if(!ok) cout << "NA" << endl;
	}
}