#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int diff_row[4] = {0,-1,0,1},diff_col[4] = {1,0,-1,0};
int diff_row_N[4] = {0,-1,0,1},diff_col_N[4] = {1,0,-1,0};
int diff_row_E[4] = {1,0,-1,0},diff_col_E[4] = {0,1,0,-1};
int diff_row_S[4] = {0,1,0,-1},diff_col_S[4] = {-1,0,1,0};
int diff_row_W[4] = {-1,0,1,0},diff_col_W[4] = {0,-1,0,1};

char array[4] = {'W','S','E','N'};

int W,H;
char map[30][31],calc[128];


bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

void func(){

	int num = 0;

	for(int i = 0; i < H; i++){
		scanf("%s",map[i]);
		for(int k = 0; k < W; k++){
			if(map[i][k] == 'N' || map[i][k] == 'E' || map[i][k] == 'S' || map[i][k] == 'W')num++;
		}
	}

	int ans = -1;
	int next_row,next_col;

	for(int time = 1; time <= 180; time++){
		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				switch(map[row][col]){
				case 'N':
					for(int i = 0; i < 4; i++){
						next_row = row + diff_row_N[i];
						next_col = col + diff_col_N[i];
						if(map[next_row][next_col] == '.' || map[next_row][next_col] == 'X'){
							switch(i){
							case 0:
								map[row][col] = 'E';
								break;
							case 1:
								//Do nothing
								break;
							case 2:
								map[row][col] = 'W';
								break;
							case 3:
								map[row][col] = 'S';
								break;
							}
							break;
						}
					}
					break;
				case 'E':
					for(int i = 0; i < 4; i++){
						next_row = row + diff_row_E[i];
						next_col = col + diff_col_E[i];
						if(map[next_row][next_col] == '.' || map[next_row][next_col] == 'X'){
							switch(i){
							case 0:
								map[row][col] = 'S';
								break;
							case 1:
								//Do nothing
								break;
							case 2:
								map[row][col] = 'N';
								break;
							case 3:
								map[row][col] = 'W';
								break;
							}
							break;
						}
					}
					break;
				case 'S':
					for(int i = 0; i < 4; i++){
						next_row = row + diff_row_S[i];
						next_col = col + diff_col_S[i];
						if(map[next_row][next_col] == '.' || map[next_row][next_col] == 'X'){
							switch(i){
							case 0:
								map[row][col] = 'W';
								break;
							case 1:
								//Do nothing
								break;
							case 2:
								map[row][col] = 'E';
								break;
							case 3:
								map[row][col] = 'N';
								break;
							}
							break;
						}
					}
					break;
				case 'W':
					for(int i = 0; i < 4; i++){
						next_row = row + diff_row_W[i];
						next_col = col + diff_col_W[i];
						if(map[next_row][next_col] == '.' || map[next_row][next_col] == 'X'){
							switch(i){
							case 0:
								map[row][col] = 'N';
								break;
							case 1:
								//Do nothing
								break;
							case 2:
								map[row][col] = 'S';
								break;
							case 3:
								map[row][col] = 'E';
								break;
							}
							break;
						}
					}
					break;
				}
			}
		}

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				if(map[row][col] == '.'){
					for(int i = 0; i < 4; i++){
						next_row = row + diff_row[i];
						next_col = col + diff_col[i];

						if(rangeCheck(next_row,next_col) == true && map[next_row][next_col] == array[i]){
							map[row][col] = calc[map[next_row][next_col]];
							map[next_row][next_col] = '@';
							break;
						}
					}
				}else if(map[row][col] == 'X'){
					for(int i = 0; i < 4; i++){
						next_row = row + diff_row[i];
						next_col = col + diff_col[i];

						if(rangeCheck(next_row,next_col) == true && map[next_row][next_col] == array[i]){
							map[next_row][next_col] = '@';
							num--;
							break;
						}
					}
				}
			}
		}

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				switch(map[row][col]){
				case 'n':
				case 'e':
				case 's':
				case 'w':
					map[row][col] = calc[map[row][col]];
					break;
				case '@':
					map[row][col] = '.';
					break;
				}
			}
		}

		if(num == 0){
			ans = time;
			break;
		}
	}

	if(ans == -1){
		printf("NA\n");
	}else{
		printf("%d\n",ans);
	}
}

int main(){

	calc['N'] = 'n';
	calc['E'] = 'e';
	calc['S'] = 's';
	calc['W'] = 'w';
	calc['n'] = 'N';
	calc['e'] = 'E';
	calc['s'] = 'S';
	calc['w'] = 'W';

	while(true){
		scanf("%d %d",&W,&H);
		if(H == 0 && W == 0)break;

		func();
	}

	return 0;
}