#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <unordered_set>
//#include <unordered_map>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;


int h,w;
stringstream ss;
 









int dy[4][4]={{1,0,-1,0},
			  {0,-1,0,1},
			  {-1,0,1,0},
			  {0,1,0,-1}};
int dx[4][4]={{0,1,0,-1},
			  {1,0,-1,0},
			  {0,-1,0,1},
			  {-1,0,1,0}};
int dd[4][4]={{4,1,2,3},
			  {1,2,3,4},
			  {2,3,4,1},
			  {3,4,1,2}};
int dy2[4]={0,1,0,-1};
int dx2[4]={-1,0,1,0};

void mainmain(){
	while(cin>>w>>h,h||w){
		vvint vv;
		initvv(vv,h+2,w+2,-1);
		int n=0;
		reep(i,1,h+1){
			string s;
			cin>>s;
			reep(j,1,w+1){
				char t=s[j-1];
				// maps[i-1][j-1]=t;
				if(t=='#'){
					vv[i][j]=-1;
				}
				else if(t=='.'){
					vv[i][j]=0;
				}
				else if(t=='X'){
					vv[i][j]=-2;
				}
				else if(t=='E'){
					vv[i][j]=1;
					n++;
				}
				else if(t=='N'){
					vv[i][j]=2;
					n++;
				}
				else if(t=='W'){
					vv[i][j]=3;
					n++;
				}
				else if(t=='S'){
					vv[i][j]=4;
					n++;
				}
			}
		}
		// if(cc==204){
			// cout<<w<<" "<<h<<" "<<endl;
			// rep(i,h){
				// rep(j,w){
					// cout<<maps[i][j];
				// }
				// cout<<endl;
			// }
			// cout<<0<<" "<<0<<endl;
		// }
		// continue;
		vvint used;
		initvv(used,h+2,w+2);
		bool f=false;
		int cnt=0;
		rep(i,180){
			// if(i>10) break;
			// rep(k,vv.size()){
				// rep(j,vv[0].size()){
					// printf("%2d",vv[k][j]);
				// }
				// cout<<endl;
			// }
			// cout<<endl;
			rep(k,h+2){
				rep(j,w+2){
					used[k][j]=0;
				}
			}
			reep(j,1,h+1){
				reep(k,1,w+1){
					if(vv[j][k]>=1){
						rep(l,4){
							int y=j+dy[vv[j][k]-1][l];
							int x=k+dx[vv[j][k]-1][l];
							if(1<=y&&y<h+1&&1<=x&&x<w+1){
								if(vv[y][x]==0||vv[y][x]==-2){
									vv[j][k]=dd[vv[j][k]-1][l];
									break;
								}
							}
						}
					}
				}
			}
			int o=0;
				reep(j,1,h+1){
					reep(k,1,w+1){
						if(vv[j][k]==(o+2)%4+1){
							int y=j+dy2[o];
							int x=k+dx2[o];
							if(1<=y&&y<h+1&&1<=x&&x<w+1);
							else continue; 
							// cout<<j<<" "<<k<<" "<<dy2[o]<<" "<<dx2[o]<<endl;
							// cout<<y<<" "<<x<<endl;
							if(vv[y][x]==-2&&used[y][x]==0&&used[j][k]==0){
								cnt++;
								vv[j][k]=0;
								used[y][x]=1;
								used[j][k]=1;
							}
							else if(vv[y][x]==0&&used[j][k]==0&&used[y][k]==0){
								used[j][k]=1;
								vv[j][k]=0;
								vv[y][x]=(o+2)%4+1;
								used[y][x]=1;
							}
						}
					}
				}
			o=1;
				for(int j=h;j>=1;j--){
					reep(k,1,w+1){
						if(vv[j][k]==(o+2)%4+1){
							int y=j+dy2[o];
							int x=k+dx2[o];
							if(1<=y&&y<h+1&&1<=x&&x<w+1);
							else continue; 
							// cout<<j<<" "<<k<<" "<<dy2[o]<<" "<<dx2[o]<<endl;
							// cout<<y<<" "<<x<<endl;
							if(vv[y][x]==-2&&used[y][x]==0&&used[j][k]==0){
								cnt++;
								vv[j][k]=0;
								used[y][x]=1;
								used[j][k]=1;
							}
							else if(vv[y][x]==0&&used[j][k]==0&&used[y][x]==0){
								vv[j][k]=0;
								vv[y][x]=(o+2)%4+1;
								used[y][x]=1;
								used[j][k]=1;
							}
						}
					}
				}
			o=2;
				reep(j,1,h+1){
					for(int k=w;k>=1;k--){
						if(vv[j][k]==(o+2)%4+1){
							int y=j+dy2[o];
							int x=k+dx2[o];
							if(1<=y&&y<h+1&&1<=x&&x<w+1);
							else continue; 
							// cout<<j<<" "<<k<<" "<<dy2[o]<<" "<<dx2[o]<<endl;
							// cout<<y<<" "<<x<<endl;
							if(vv[y][x]==-2&&used[y][x]==0&&used[j][k]==0){
								cnt++;
								vv[j][k]=0;
								used[y][x]=1;
								used[j][k]=1;
							}
							else if(vv[y][x]==0&&used[j][k]==0&&used[y][x]==0){
								vv[j][k]=0;
								vv[y][x]=(o+2)%4+1;
								used[y][x]=1;
								used[j][k]=1;
							}
						}
					}
				}
			o=3;
				reep(j,1,h+1){
					reep(k,1,w+1){
						if(vv[j][k]==(o+2)%4+1){
							int y=j+dy2[o];
							int x=k+dx2[o];
							if(1<=y&&y<h+1&&1<=x&&x<w+1);
							else continue; 
							// cout<<j<<" "<<k<<" "<<dy2[o]<<" "<<dx2[o]<<endl;
							// cout<<y<<" "<<x<<endl;
							if(vv[y][x]==-2&&used[y][x]==0&&used[j][k]==0){
								cnt++;
								vv[j][k]=0;
								used[y][x]=1;
								used[j][k]=1;
							}
							else if(vv[y][x]==0&&used[j][k]==0&&used[y][x]==0){
								vv[j][k]=0;
								vv[y][x]=(o+2)%4+1;
								used[j][k]=1;
								used[y][x]=1;
							}
						}
					}
				}
			if(cnt==n){
				ss<<i+1<<endl;
				f=true;
				break;
			}
		}
		if(!f){
			ss<<"NA\n";
		}
		string s1;
		ss>>s1;
		cout<<s1<<endl;
		// cout<<s1<<" "<<s2<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}