// 2011/08/05 Tazoe

#include <iostream>
using namespace std;

struct man{
	int x;
	int y;
	int d;
};

int main()
{
	while(true){
		int W, H;
		cin >> W >> H;
		if(W==0&&H==0)
			break;

		char S[30][30];
		struct man M[900];
		int N = 0;
		for(int y=0; y<H; y++){
			for(int x=0; x<W; x++){
				cin >> S[y][x];

				if(S[y][x]=='E'||S[y][x]=='N'||S[y][x]=='W'||S[y][x]=='S'){
					M[N].x = x;
					M[N].y = y;
					if(S[y][x]=='E')
						M[N].d = 2;
					else if(S[y][x]=='N')
						M[N].d = 3;
					else if(S[y][x]=='W')
						M[N].d = 0;
					else if(S[y][x]=='S')
						M[N].d = 1;
					N++;
					S[y][x] = '@';
				}
			}
		}

		bool flg = false;
		for(int t=1; t<=180; t++){
			for(int i=0; i<N; i++){
				int D = (M[i].d+4-1)%4;
				for(int j=0; j<4; j++){
					if(D==2&&(S[M[i].y][M[i].x+1]=='.'||S[M[i].y][M[i].x+1]=='X'))
						break;
					else if(D==3&&(S[M[i].y-1][M[i].x]=='.'||S[M[i].y-1][M[i].x]=='X'))
						break;
					else if(D==0&&(S[M[i].y][M[i].x-1]=='.'||S[M[i].y][M[i].x-1]=='X'))
						break;
					else if(D==1&&(S[M[i].y+1][M[i].x]=='.'||S[M[i].y+1][M[i].x]=='X'))
						break;
					if(j<3)
						D = (D+1)%4;
					else
						D = M[i].d;
				}
				M[i].d = D;
			}

			for(int i=0; i<N-1; i++)
				for(int j=i+1; j<N; j++)
					if(M[i].d>M[j].d){
						struct man tmp = M[i];
						M[i] = M[j];
						M[j] = tmp;
					}

			for(int i=0; i<N; i++)
				if(M[i].d==2&&(S[M[i].y][M[i].x+1]=='.'||S[M[i].y][M[i].x+1]=='X')){
					if(S[M[i].y][M[i].x+1]=='X')
						M[i].d = 9;
					S[M[i].y][M[i].x] = '.';
					M[i].x += 1;
					S[M[i].y][M[i].x] = '@';
				}
				else if(M[i].d==3&&(S[M[i].y-1][M[i].x]=='.'||S[M[i].y-1][M[i].x]=='X')){
					if(S[M[i].y-1][M[i].x]=='X')
						M[i].d = 9;
					S[M[i].y][M[i].x] = '.';
					M[i].y -= 1;
					S[M[i].y][M[i].x] = '@';
				}
				else if(M[i].d==0&&(S[M[i].y][M[i].x-1]=='.'||S[M[i].y][M[i].x-1]=='X')){
					if(S[M[i].y][M[i].x-1]=='X')
						M[i].d = 9;
					S[M[i].y][M[i].x] = '.';
					M[i].x -= 1;
					S[M[i].y][M[i].x] = '@';
				}
				else if(M[i].d==1&&(S[M[i].y+1][M[i].x]=='.'||S[M[i].y+1][M[i].x]=='X')){
					if(S[M[i].y+1][M[i].x]=='X')
						M[i].d = 9;
					S[M[i].y][M[i].x] = '.';
					M[i].y += 1;
					S[M[i].y][M[i].x] = '@';
				}

			for(int i=0; i<N; i++)
				if(M[i].d==9)
					S[M[i].y][M[i].x] = 'X';

			for(int i=0; i<N-1; i++)
				for(int j=i+1; j<N; j++)
					if(M[i].d>M[j].d){
						struct man tmp = M[i];
						M[i] = M[j];
						M[j] = tmp;
					}

			for(int i=0; i<N; i++)
				if(M[i].d==9){
					N = i;
					break;
				}
/*
			char S2[30][30];
			for(int y=0; y<H; y++)
				for(int x=0; x<W; x++)
					S2[y][x] = S[y][x];

			for(int i=0; i<N; i++)
				if(M[i].d==2)
					S2[M[i].y][M[i].x] = 'E';
				else if(M[i].d==3)
					S2[M[i].y][M[i].x] = 'N';
				else if(M[i].d==0)
					S2[M[i].y][M[i].x] = 'W';
				else if(M[i].d==1)
					S2[M[i].y][M[i].x] = 'S';

			for(int y=0; y<H; y++){
				for(int x=0; x<W; x++)
					cout << S2[y][x];
				cout << endl;
			}
			break;
*/
			if(N==0){
				cout << t << endl;
				flg = true;
				break;
			}
		}

		if(!flg)
			cout << "NA" << endl;
	}

	return 0;
}