#include <iostream>
#include <cstring>
#include <cassert>
#include <vector>
#include <string>

using namespace std;

#define MAX_H 30
#define MAX_W 30

int W, H;
string F[MAX_H];
bool flag[MAX_H][MAX_W];
int t;

bool person(int y, int x) {
    return (F[y][x] == 'E' || F[y][x] == 'N' || F[y][x] == 'W' || F[y][x] == 'S');
}

bool finish() {
    for (int i = 0; i < H; i++) 
        for (int j = 0; j < W; j++)
            if (person(i, j))
                return false;
    return true;
}

char next_dir(char dir) {
    switch (dir) {
        case 'E':
            return 'N';
        case 'N':
            return 'W';
        case 'W':
            return 'S';
        case 'S':
            return 'E';
    }
}

char prev_dir(char dir) {
    switch (dir) {
        case 'E':
            return 'S';
        case 'N':
            return 'E';
        case 'W':
            return 'N';
        case 'S':
            return 'W';
    }
}

bool forward_free(int y, int x, char dir) {
    switch (dir) {
        case 'E':
            if (0 <= x + 1 && x + 1 < W && (F[y][x+1] == '.' || F[y][x+1] == 'X')) return true;
            return false;
        case 'N':
            if (0 <= y - 1 && y - 1 < H && (F[y-1][x] == '.' || F[y-1][x] == 'X')) return true;
            return false;
        case 'W':
            if (0 <= x - 1 && x - 1 < W && (F[y][x-1] == '.' || F[y][x-1] == 'X')) return true;
            return false;
        case 'S':
            if (0 <= y + 1 && y + 1 < H && (F[y+1][x] == '.' || F[y+1][x] == 'X')) return true;
            return false;
    }
}

bool mark_forward(int y, int x, char dir) {
    switch (dir) {
        case 'E':
            flag[y][x+1] = true;
            break;
        case 'N':
            flag[y-1][x] = true;
            break;
        case 'W':
            flag[y][x-1] = true;
            break;
        case 'S':
            flag[y+1][x] = true;
            break;
    }
}

void step() {
    memset(flag, 0, sizeof(flag));
    if (false) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << F[i][j] << ' ';
            }
            cout << endl;
        }
    }
    t++;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (person(i, j)) {
                char dir = prev_dir(F[i][j]);
                for (int k = 0; k < 4; k++) {
                    if (forward_free(i, j, dir)) {
                        F[i][j] = dir;
                        mark_forward(i, j, dir);
                        break;
                    }
                    dir = next_dir(dir);
                }
            }
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (flag[i][j]) {
                if (person(i, j+1)) {
                    if (F[i][j] != 'X') F[i][j] = F[i][j+1];
                    F[i][j+1] = '.';
                } else if (person(i-1, j)) {
                    if (F[i][j] != 'X') F[i][j] = F[i-1][j];
                    F[i-1][j] = '.';
                } else if (person(i, j-1)) {
                    if (F[i][j] != 'X') F[i][j] = F[i][j-1];
                    F[i][j-1] = '.';
                } else if (person(i+1, j)) {
                    if (F[i][j] != 'X') F[i][j] = F[i+1][j];
                    F[i+1][j] = '.';
                } else {
                    assert(false);
                }
            }
        }
    }
}

int main() {
    while (cin >> W >> H, W || H) {
        t = 0;
        for (int i = 0; i < H; i++) cin >> F[i];
        while (!finish() && t <= 180) {
            step();
        }
        if (t == 181) cout << "NA" << endl;
        else cout << t << endl;
    }
    return 0;
}