#include<bits/stdc++.h>
using namespace std;

const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

int W,H;
char fld[50][50];

int calc(){
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(!isdigit(fld[i][j]))continue;
            int dir=fld[i][j]-'0';
            for(int d=1;d>=-2;d--){
                int nd=(dir+d+4)%4;
                int ny=i+dy[nd],nx=j+dx[nd];
                if(ny<0||ny>=H||nx<0||nx>=W||(fld[ny][nx]!='X'&&fld[ny][nx]!='.'))continue;
                fld[i][j]=nd+'0';
                break;
            }
        }
    }
    int ret=0;
    char nfld[50][50];
    bool ok[50][50]={{0}};
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(fld[i][j]=='#'||isdigit(fld[i][j]))continue;
            for(int d=0;d>=-3;d--){
                int nd=(d+4)%4;
                int ny=i+dy[nd],nx=j+dx[nd];
                if(ny<0||ny>=H||nx<0||nx>=W)continue;
                if(!isdigit(fld[ny][nx])||fld[ny][nx]!='0'+(nd+2)%4)continue;
                ok[ny][nx]=true;
                break;
            }
        }
    }

    for(int i=0;i<H;i++)for(int j=0;j<W;j++)nfld[i][j]='*';
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(nfld[i][j]!='*')continue;
            if(ok[i][j]){
                int ny=i+dy[fld[i][j]-'0'];
                int nx=j+dx[fld[i][j]-'0'];
                if(fld[ny][nx]!='X'){
                    nfld[ny][nx]=fld[i][j];
                    nfld[i][j]='.';
                }
                else{
                    nfld[ny][nx]='X';
                    nfld[i][j]='.';
                    ret++;
                }
            }
            else{
                nfld[i][j]=fld[i][j];
            }

        }
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            fld[i][j]=nfld[i][j];
        }
    }

    return ret;
}

int main(){

    while(cin>>W>>H,W||H){
        int cnt=0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cin>>fld[i][j];
                switch(fld[i][j]){
                case 'E':fld[i][j]='0';break;
                case 'S':fld[i][j]='1';break;
                case 'W':fld[i][j]='2';break;
                case 'N':fld[i][j]='3';break;
                }
                if(isdigit(fld[i][j]))cnt++;

            }
        }

        for(int i=1;i<=180;i++){
            cnt-=calc();
            if(cnt==0){
                cout<<i<<endl;
                break;
            }
        }
        if(cnt)cout<<"NA"<<endl;
    }
    return 0;
}