#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};

int main(){
    char board[30][31],nextboard[30][30];
    int chk[30][30];
    
    for(int w,h;cin>>w>>h,w;){
        for(int i=0;i<h;i++) cin>>board[i];
        
        int man=0;
        for(int i=0;i<h;i++)for(int j=0;j<w;j++){
            if(board[i][j]!='.' && board[i][j]!='X' && board[i][j]!='#'){
                if     (board[i][j]=='E')    board[i][j]=0;
                else if(board[i][j]=='N')    board[i][j]=1;
                else if(board[i][j]=='W')    board[i][j]=2;
                else if(board[i][j]=='S')    board[i][j]=3;
                man++;
            }
        }
        
        int ans=-1;
        for(int t=0;t<=180;t++){
            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(board[i][j]>3) continue;
                for(int k=0,l=(board[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 && (board[y][x]=='.' || board[y][x]=='X')){
                        board[i][j]=l;
                        chk[y][x]=min(chk[y][x],(l+2)%4);
                        break;
                    }
                }
            }
            
            for(int i=0;i<h;i++)for(int j=0;j<w;j++)  nextboard[i][j]=board[i][j];
            
            for(int i=0;i<h;i++)for(int j=0;j<w;j++){
                if(board[i][j]>3) continue;
                int y=i+dy[board[i][j]],x=j+dx[board[i][j]];
                if(0<=y && y<h && 0<=x && x<w && chk[y][x]==(board[i][j]+2)%4){ 
                    if(board[y][x]=='.') nextboard[y][x]=board[i][j];
                    else if(board[y][x]=='X')    man--;
                    else{while(1);}
                    nextboard[i][j]='.';
                }
            }
            for(int i=0;i<h;i++)for(int j=0;j<w;j++)  board[i][j]=nextboard[i][j];
        }
        
        if(ans >= 0)    cout<<ans<<endl;
        else        cout<<"NA"<<endl;
    }
    
    return 0;
}