#include<iostream>

#define	mp	make_pair
#define	pb	push_back

using namespace std;

typedef	pair<int,int>	pii;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
//#define DEBUG 0
int main(){
	char maze[30][31],nextmaze[30][30];
	int chk[30][30];

	for(int w,h;cin>>w>>h,w;){
		for(int i=0;i<h;i++)	cin>>maze[i];

		int man=0;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			if(maze[i][j]!='.' && maze[i][j]!='X' && maze[i][j]!='#'){
				if     (maze[i][j]=='E')	maze[i][j]=0;
				else if(maze[i][j]=='N')	maze[i][j]=1;
				else if(maze[i][j]=='W')	maze[i][j]=2;
				else if(maze[i][j]=='S')	maze[i][j]=3;
				man++;
			}
		}

		int ans=-1;
		for(int t=0;t<=19;t++){
#ifdef DEBUG
cout<<"t="<<t<<endl;
for(int i=0;i<h;i++){for(int j=0;j<w;j++){
if(maze[i][j]==0)cout<<"E ";
else if(maze[i][j]==1)cout<<"N ";
else if(maze[i][j]==2)cout<<"W ";
else if(maze[i][j]==3)cout<<"S ";
else	cout<<maze[i][j]<<" ";
}cout<<endl;}cout<<endl;
#endif
			if(man==0){ ans=t; break; }

			for(int i=0;i<h;i++)for(int j=0;j<w;j++)	chk[i][j]=777;

			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				if(maze[i][j]>3)	continue;
				for(int k=0,l=(maze[i][j]+3)%4;k<4;k++,l=(l+1)%4){
					int y=i+dy[l],x=j+dx[l];
					if(0<=y && y<h && 0<=x && x<w
					&&(maze[y][x]=='.' || maze[y][x]=='X')){
						maze[i][j]=l;
						chk[y][x]=min(chk[y][x],(l+2)%4);
						break;
					}
				}
			}
#ifdef DEBUG
for(int i=0;i<h;i++){for(int j=0;j<w;j++){
if(chk[i][j]>100)cout<<"x ";
else	cout<<chk[i][j]<<" ";
}cout<<endl;}cout<<endl;
#endif
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)	nextmaze[i][j]=maze[i][j];

			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				if(maze[i][j]>3)	continue;
				int y=i+dy[maze[i][j]],x=j+dx[maze[i][j]];
				if(0<=y && y<h && 0<=x && x<w && (chk[y][x]+2)%4==maze[i][j]){	// movable
					nextmaze[i][j]='.';
					if(maze[y][x]=='.')	nextmaze[y][x]=maze[i][j];
					else if(maze[y][x]=='X')	man--;
				}
			}

			for(int i=0;i<h;i++)for(int j=0;j<w;j++)	maze[i][j]=nextmaze[i][j];
		}

		if(~ans)	cout<<ans<<endl;
		else		cout<<"NA"<<endl;
	}

	return 0;
}