#include<iostream>
#define ck(a,b) 0<=a&&a<b
#define enws(a) (a=='E'||a=='N'||a=='W'||a=='S')
#define dir(a) (a!='E'?a!='N'?a!='W'?3:2:1:0)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int main(){
	int w,h,t,rest;char m[31][31],nm[31][31];
	while(cin>>w>>h,w){
		rest=0;
		rep(i,h){
			cin>>m[i];
			rep(j,w)if(enws(m[i][j]))rest++;
		}
		for(t=0;rest&&t<181;t++){
			rep(i,h)rep(j,w){
				if(enws(m[i][j])){
					int cd=dir(m[i][j]),nd,ny,nx;
					rep(d,4){
						nd=cd+d+3&3;
						ny=i+dy[nd],nx=j+dx[nd];
						if(ck(ny,h)&&ck(nx,w)&&(m[ny][nx]=='.'||m[ny][nx]=='X')){
							m[i][j]="ENWS"[nd]; break;
						}
					}
				}
				nm[i][j]=m[i][j];
			}
			rep(i,h)rep(j,w)if(m[i][j]=='.'||m[i][j]=='X'){
				rep(d,4){
					int ny=i+dy[d],nx=j+dx[d];
					if(ck(ny,h)&&ck(nx,w)&&m[ny][nx]=="WSEN"[d]){
						if(m[i][j]=='.')nm[i][j]=m[ny][nx];
						else rest--;
						nm[ny][nx]='.';
						break;
					}
				}
			}
			rep(i,h)rep(j,w)m[i][j]=nm[i][j];
		}
		if(t<=180)cout<<t<<endl;
		else cout<<"NA"<<endl;
	}
	return 0;
}