#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int w, h;
char field[100][100];
int pdir[110][110];
int mapto[300];
int mapfrom[300];
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, -1, 0, 1 };

void PrintField() {
  REP(y, h) {
    printf("%s\n", field[y]);
  }
  puts("");
}

void Push(int nx, int ny, int dir) {
  if (dir == 2) { pdir[ny][nx] = dir; }
  if (pdir[ny][nx] == 2) { return; }
  if (dir == 3) { pdir[ny][nx] = dir; }
  if (pdir[ny][nx] == 3) { return; }
  if (dir == 0) { pdir[ny][nx] = dir; }
  if (pdir[ny][nx] == 0) { return; }
  if (dir == 1) { pdir[ny][nx] = dir; }
  if (pdir[ny][nx] == 1) { return; }
}

int Person() {
  int ret = 0;
  REP(y, h) {
    REP(x, w) {
      if (mapto[(int)field[y][x]] <= 3) { ret++; }
    }
  }
  return ret;
}

int main() {
  MEMSET(mapto, 0x0f);
  mapto[(int)'E'] = 0;
  mapto[(int)'N'] = 1;
  mapto[(int)'W'] = 2;
  mapto[(int)'S'] = 3;
  mapfrom[0] = 'E';
  mapfrom[1] = 'N';
  mapfrom[2] = 'W';
  mapfrom[3] = 'S';
  while (scanf("%d %d", &w, &h), w|h) {
    REP(y, h) {
      scanf("%s", field[y]);
    }
    REP(t, 181) {
      MEMSET(pdir, 0x0f);
      if (Person() == 0) {
        printf("%d\n", t);
        goto next;
      }
      REP(y, h) {
        REP(x, w) {
          int dir = mapto[(int)field[y][x]];
          if (dir <= 3) {
            REP(i, 4) {
              int ndir = (dir + i + 3) % 4;
              int nx = x + dx[ndir];
              int ny = y + dy[ndir];
              if (field[ny][nx] == '.' ||
                  field[ny][nx] == 'X') {
                Push(nx, ny, ndir);
                break;
              }
            }
          }
        }
      }
      REP(y, h) {
        REP(x, w) {
          int dir = pdir[y][x];
          if (dir <= 3) {
            int px = x + dx[(dir + 2) % 4];
            int py = y + dy[(dir + 2) % 4];
            field[py][px] = '.';
            if (field[y][x] == '.') {
              field[y][x] = mapfrom[dir];
            }
          }
        }
      }
    }
    puts("NA");
next:;
  }
}