#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

void solve(vs grid)
{
	int h=grid.size(),w=grid[0].size();
	char dir[]="ENWS";
	int di[]={0,-1,0,1},dj[]={1,0,-1,0};
	
	for(int t=0;t<=180;t++){
		bool escaped=true;
		rep(i,h) rep(j,w)
			escaped&=!strchr(dir,grid[i][j]);
		if(escaped){
			cout<<t<<endl;
			return;
		}
		
		rep(i,h) rep(j,w) if(strchr(dir,grid[i][j])){
			int cd=strchr(dir,grid[i][j])-dir;
			rep(k,4){
				int nd=(cd+3+k)%4;
				int ni=i+di[nd],nj=j+dj[nd];
				if(ni<0 || h<=ni || nj<0 || w<=nj || !(grid[ni][nj]=='.' || grid[ni][nj]=='X'))
					continue;
				grid[i][j]=dir[nd];
				break;
			}
		}
		
		vs grid2=grid;
		rep(i,h) rep(j,w) if(grid[i][j]=='.' || grid[i][j]=='X'){
			rep(k,4){
				int pi=i+di[k],pj=j+dj[k];
				if(pi<0 || h<=pi || pj<0 || w<=pj || grid[pi][pj]!=dir[(k+2)%4])
					continue;
				if(grid[i][j]=='.')
					grid2[i][j]=grid[pi][pj];
				grid2[pi][pj]='.';
				break;
			}
		}
		grid=grid2;
	}
	cout<<"NA"<<endl;
}

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		vs grid(h);
		rep(i,h) cin>>grid[i];
		
		solve(grid);
	}
	
	return 0;
}