#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

enum class Direction {
	East, North, West, South
};
enum class RelationalDirection {
	Right, Forward, Left, Backward
};
constexpr std::array<Direction, 4> Directions{ Direction::East, Direction::North, Direction::West, Direction::South };
constexpr std::array<RelationalDirection, 4> RelationalDirestions{ RelationalDirection::Right, RelationalDirection::Forward, RelationalDirection::Left, RelationalDirection::Backward };

int to_int(Direction dir) {
	switch (dir) {
	case Direction::East: return 0;
	case Direction::North: return 1;
	case Direction::West: return 2;
	case Direction::South: return 3;
	default: throw 0;
	}
}
int to_int(RelationalDirection dir) {
	switch (dir) {
	case RelationalDirection::Right: return 3;
	case RelationalDirection::Forward: return 0;
	case RelationalDirection::Left: return 1;
	case RelationalDirection::Backward: return 2;
	default: throw 0;
	}
}

Direction operator+(Direction dir, RelationalDirection rdir) {
	return Directions[(to_int(dir) + to_int(rdir)) % 4];
}
Direction operator+(RelationalDirection rdir, Direction dir) {
	return Directions[(to_int(rdir) + to_int(dir)) % 4];
}

struct Coordinate {
	int x, y;
};
Coordinate from_dir(Direction dir) {
	switch (dir) {
	case Direction::East: return Coordinate{ 1, 0 };
	case Direction::North: return Coordinate{ 0, -1 };
	case Direction::West: return Coordinate{ -1, 0 };
	case Direction::South: return Coordinate{ 0, 1 };
	default: throw 0;
	}
}
Coordinate operator+(Coordinate a, Coordinate b) {
	return Coordinate{ a.x + b.x, a.y + b.y };
}
Coordinate operator+(Coordinate a, Direction dir) {
	return a + from_dir(dir);
}
Coordinate operator+(Direction dir, Coordinate a) {
	return from_dir(dir) + a;
}
bool operator==(Coordinate a, Coordinate b) {
	return a.x == b.x && a.y == b.y;
}

struct Person {
	Coordinate position;
	Direction dir;
};

int main() {
	while (true) {
		int width, height; std::cin >> width >> height; if (width == 0 && height == 0) break;
		std::vector<std::string> state(height); for (auto& line : state) std::cin >> line;
		std::vector<Person> person;
		for (auto i = 0; i < height; ++i) for (auto j = 0; j < width; ++j) {
			switch (state[i][j]) {
			case 'E': person.push_back(Person{ Coordinate{j, i}, Direction::East }); break;
			case 'N': person.push_back(Person{ Coordinate{j, i}, Direction::North }); break;
			case 'W': person.push_back(Person{ Coordinate{j, i}, Direction::West }); break;
			case 'S': person.push_back(Person{ Coordinate{j, i}, Direction::South }); break;
			default: break;
			}
		}
		std::vector<Coordinate> next_pos(person.size());
		std::vector<std::vector<int>> id(height, std::vector<int>(width, -1));
		std::vector<std::vector<bool>> is_in_queue(height, std::vector<bool>(width, false));
		std::queue<int> in_maze; for (auto i = 0; i < person.size(); ++i) {
			in_maze.push(i);
			id[person[i].position.y][person[i].position.x] = i;
		}
		std::queue<Coordinate> move_target;
		int count = -1;
		for (; count <= 180 && !in_maze.empty(); ++count) {
			for (auto c = in_maze.size(); c > 0; --c) {
				auto top = in_maze.front(); in_maze.pop();
				if (state[person[top].position.y][person[top].position.x] == 'X') continue;
				for (const auto dir : RelationalDirestions) {
					auto next = person[top].position + (person[top].dir + dir);
					if (state[next.y][next.x] != '#' && id[next.y][next.x] == -1) {
						if (!is_in_queue[next.y][next.x]) {
							is_in_queue[next.y][next.x] = true;
							move_target.push(next);
						}
						person[top].dir = person[top].dir + dir;
						next_pos[top] = next;
						break;
					}
				}
				in_maze.push(top);
			}
			while (!move_target.empty()) {
				auto top = move_target.front(); move_target.pop();
				is_in_queue[top.y][top.x] = false;
				for (const auto dir : Directions) {
					auto suspect = top + dir;
					if (0 <= suspect.y && suspect.y < height && 0 <= suspect.x && suspect.x < width && id[suspect.y][suspect.x] != -1 && next_pos[id[suspect.y][suspect.x]] == top) {
						if (state[top.y][top.x] != 'X') {
							id[top.y][top.x] = id[suspect.y][suspect.x];
						}
						person[id[suspect.y][suspect.x]].position = top;
						id[suspect.y][suspect.x] = -1;
						break;
					}
				}
			}
		}
		if (count > 180) {
			std::cout << "NA\n";
		}
		else {
			std::cout << count << '\n';
		}
	}
}


Measured memory_bytes: 3192