#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<sstream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define reps(i,n) for(int i = 1; i <= (n); i++)
#define PII pair<int,int>
#define PP pair< int,PII >

using namespace std;

int W,H;
char cell[32][32];
char map[32][32];

int newsm[4][2] = {{-1, 0}, {0,-1}, {1, 0}, {0,1}};
char news[] = "WNES";
int move[] = {1, 0, 3, 2};	//方角を見る順番

int canMove(char x){
	if(x == 'X' || x == '.')
		return 1;
	return 0;
}

void step1(){
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if('A' < map[i][j] && map[i][j] < 'X'){
				for(int k = 0; k < 4; k++){
					if(map[i][j] == news[k]){
						for(int l = 0; l < 4; l++){
							if(canMove(map[i+newsm[(k+move[l])%4][1]][j+newsm[(k+move[l])%4][0]])){
								map[i][j] = news[(k+move[l])%4];
								break;
							}
						}
						break;
					}
				}
			}
		}
	}
}

void step2(){
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cell[i][j] = -1;
		}
	}
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if('A' < map[i][j] && map[i][j] < 'X'){
				for(int k = 0; k < 4; k++){
					if(map[i][j] == news[k]){
						if(cell[i+newsm[k][1]][j+newsm[k][0]] == -1){
							cell[i+newsm[k][1]][j+newsm[k][0]] = map[i][j];
							map[i][j] = '.';
						}else{
							cell[i][j] = map[i][j];
						}
					}
				}
			}
		}
	}
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(cell[i][j] != -1 && map[i][j] == '.'){
				map[i][j] = cell[i][j];
			}
		}
	}
}

int step3(){
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if('A' < map[i][j] && map[i][j] < 'X'){
				return 1;
			}
		}
	}
	return 0;
}

int main(void){
	
	while(1){
		int i;
		scanf("%d%d", &W, &H);
		if(H==0)break;
		rep(i,H)
			scanf("%s", map[i]);
		for(i = 1; i < 180; i++){
			step1();
			//rep(i,H)puts(map[i]);
			step2();
			//rep(i,H)puts(map[i]);
			if(!step3()){
				break;
			}
		}
		if(i == 181){
			puts("NA");
		}else{
			printf("%d\n", i);
		}
	}
	return 0;
}