#include <iostream>
using namespace std;

int main() {

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

  while( true ) {

    int w,h;

    cin >> w >> h;

    if ( w == 0 ) break;

    int m[32][32] = {0};

    char input;

    int cnt = 0;

    for ( int i = 0; i < h + 2; i++ ) {

      for ( int j = 0; j < w + 2; j++ ) {

	if ( i == 0 || i == h+1 || j == 0 || j == w+1 ) {

	  m[j][i] = 1;
	  continue;

	}

	cin >> input;

	if ( input == '#' ) {
	  m[j][i] = 1;
	}else if ( input == '.' ) {
	  m[j][i] = 0;
	}else if ( input == 'X' ) {
	  m[j][i] = 2;
	}else if ( input == 'E' ) {
	  m[j][i] = 3;
	  cnt++;
	}else if ( input == 'N' ) {
	  m[j][i] = 4;
	  cnt++;
	}else if ( input == 'W' ) {
	  m[j][i] = 5;
	  cnt++;
	}else if ( input == 'S' ) {
	  m[j][i] = 6;
	  cnt++;
	}

      }

    }

    int t = 0;

    while( true ) {

      t++;
      if ( t > 180 ) {
	cout << "NA" << endl;
	break;
      }

      for ( int i = 1; i < h + 1; i++ ) {

	for ( int j = 1; j < w + 1; j++ ) {

	  if ( m[j][i] >= 3 ) {

	    for ( int l = 0; l < 4; l++ ) {

	      int k = ( ( m[j][i] + l ) % 4 );
	      if ( m[ j+dx[k] ][ i+dy[k] ] == 0 || m[ j+dx[k] ][ i+dy[k] ] == 2 ) {

		m[j][i] = k + 3;
		break;

	      }

	    }

	  }

	}

      }

      int c[32][32] = {0};

      while( true ) {

	bool flag = true;

      for ( int i = 1; i < h + 1; i++ ) {

	for ( int j = 1; j < w + 1; j++ ) {

	  if ( m[j][i] == 0 || m[j][i] == 2 ) {

	    for ( int l = 0; l < 4; l++ ) {

	      if ( m[ j+dx[l] ][ i+dy[l] ] >= 3 ) {

		if ( c[ j+dx[l] ][ i+dy[l] ] == 1 ) continue;
		if ( ( ( m[ j+dx[l] ][ i+dy[l] ] - l ) % 4 ) == 1 ) {

		  if ( m[j][i] == 0 ) {
		    m[j][i] = m[ j+dx[l] ][ i+dy[l] ];
		  }else {
		    cnt--;
		  }
		  m[ j+dx[l] ][ i+dy[l] ] = 0;
		  c[j][i] = 1;
		  flag = false;
		  break;

		}

	      }

	    }

	  }

	}

      }

      if ( flag == true ) break;

      }

      if ( cnt == 0 ) {
	cout << t << endl;
	break;
      }

      /*
      if ( t < 10 ) {
	for ( int i = 1; i < h + 1; i++ ) {

	  for ( int j = 1; j < w + 1; j++ ) {

	    cout << m[j][i];

	  }

	  cout << endl;

	}

      }
      */

    }

  }

  return 0;

}