#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)

string mp[40];
string next[40];

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

int main() {
  int w, h, dir;
  for (;;) {
    cin >> w >> h;
    if (w == 0 && h == 0) break;
    rep (i, h) cin >> mp[i];
    rep (time, 180) {
      //rep (i, h) cout << mp[i] << endl;
      //cout << endl;
      rep (i, h) rep (j, w) {
	if (mp[i][j] == 'N') {
	  dir = 0;
	} else if (mp[i][j] == 'W') {
	  dir = 1;
	} else if (mp[i][j] == 'S') {
	  dir = 2;
	} else if (mp[i][j] == 'E') {
	  dir = 3;
	} else {
	  continue;
	}
	rep (k, 4) {
	  if (mp[i + dy[(dir + k) % 4]][j + dx[(dir + k) % 4]] == '.'
	      || mp[i + dy[(dir + k) % 4]][j + dx[(dir + k) % 4]] == 'X') {
	    mp[i][j] = "ENWS"[(dir + k) % 4];
	    break;
	  }
	}
      }
      rep (i, h) next[i] = mp[i];
      rep (i, h) rep (j, w) {
	if (mp[i][j] == '.') {
	  if (mp[i][j + 1] == 'W') {
	    next[i][j] = 'W';
	    next[i][j + 1] = '.';
	    continue;
	  }
	  if (mp[i - 1][j] == 'S') {
	    next[i][j] = 'S';
	    next[i - 1][j] = '.';
	    continue;
	  }
	  if (mp[i][j - 1] == 'E') {
	    next[i][j] = 'E';
	    next[i][j - 1] = '.';
	    continue;
	  }
	  if (mp[i + 1][j] == 'N') {
	    next[i][j] = 'N';
	    next[i + 1][j] = '.';
	    continue;
	  }
	}
	if (mp[i][j] == 'X') {
	  if (j < w - 1 && mp[i][j + 1] == 'W') {
	    next[i][j + 1] = '.';
	    continue;
	  }
	  if (0 < i && mp[i - 1][j] == 'S') {
	    next[i - 1][j] = '.';
	    continue;
	  }
	  if (0 < j && mp[i][j - 1] == 'E') {
	    next[i][j - 1] = '.';
	    continue;
	  }
	  if (i < h - 1 && mp[i + 1][j] == 'N') {
	    next[i + 1][j] = '.';
	    continue;
	  }
	}
      }
      rep (i, h) mp[i] = next[i];
      bool end = true;
      rep (i, h) rep (j, w) {
	if (mp[i][j] == 'N') end = false;
	if (mp[i][j] == 'S') end = false;
	if (mp[i][j] == 'W') end = false;
	if (mp[i][j] == 'E') end = false;
      }
      if (end) {
	cout << time + 1 << endl;
	goto aaa;
      }
    }
    cout << "NA\n";
  aaa:;
  }
}