import copy
def hinan():
    ans = []
    while True:
        n = raw_input().split(" ")
        if n == ["0" ,"0"]:
            for an in ans:
                print an
            break
        elif len(n) == 2:
            xs = []
            k = int(n[1])
            for m in range(k):
                n = map(str,raw_input())
                xs.append(n)
            for time in range(181):
                check = []
                for i in range(len(xs)):
                    if not any(x in xs[i] for x in ["W","E","N","S"]):
                        check.append(True)
                        continue
                    else:
                        check.append(False)
                    for j in range(len(xs[i])):
                        if xs[i][j] == "S":
                            if xs[i][j - 1] in ["." ,"X"]:
                                xs[i][j] = "W"
                            elif xs[i + 1][j] in ["." ,"X"]:
                                xs[i][j] = "S"
                            elif xs[i][j + 1] in ["." ,"X"]:
                                xs[i][j] = "E"
                            elif xs[i - 1][j] in ["." ,"X"]:
                                xs[i][j] = "N"
                        elif xs[i][j] == "W":
                            if xs[i - 1][j] in ["." ,"X"]:
                                xs[i][j] = "N"
                            elif xs[i][j - 1] in ["." ,"X"]:
                                xs[i][j] = "W"
                            elif xs[i + 1][j] in ["." ,"X"]:
                                xs[i][j] = "S"
                            elif xs[i][j + 1] in ["." ,"X"]:
                                xs[i][j] = "E"
                        elif xs[i][j] == "E":
                            if xs[i + 1][j] in ["." ,"X"]:
                                xs[i][j] = "S"
                            elif xs[i][j + 1] in ["." ,"X"]:
                                xs[i][j] = "E"
                            elif xs[i - 1][j] in ["." ,"X"]:
                                xs[i][j] = "N"
                            elif xs[i][j - 1] in ["." ,"X"]:
                                xs[i][j] = "W"
                        elif xs[i][j] == "N":
                            if xs[i][j + 1] in ["." ,"X"]:
                                xs[i][j] = "E"
                            elif xs[i - 1][j] in ["." ,"X"]:
                                xs[i][j] = "N"
                            elif xs[i][j - 1] in ["." ,"X"]:
                                xs[i][j] = "W"
                            elif xs[i + 1][j] in ["." ,"X"]:
                                xs[i][j] = "S"
                ys = copy.deepcopy(xs)
                if all(check):
                    ans.append(time)
                    break
                for i in range(len(xs)):
                    for j in range(len(xs[i])):
                        if xs[i][j] == "S":
                            if xs[i + 1][j + 1] != "W":
                                if xs[i + 1][j] == "X":
                                    ys[i][j] = "."
                                    continue
                                else:
                                    ys[i + 1][j] ,ys[i][j] = "S" ,"."
                                    continue
                        elif xs[i][j] == "E":
                            if j < len(xs[i]) - 2:
                                if xs[i][j + 2] != "W" and xs[i - 1][j + 1] != "S":
                                    if xs[i][j + 1] == "X":
                                        ys[i][j] = "."
                                        continue
                                    else:
                                        ys[i][j + 1] ,ys[i][j] = "E" ,"."
                                        continue
                            else:
                                if xs[i][j + 1] == "X":
                                    ys[i][j] = "."
                                    continue
                                else:
                                    ys[i][j + 1] ,ys[i][j] = "E" ,"."
                                    continue
                        elif xs[i][j] == "W":
                            if xs[i][j - 1] == "X":
                                ys[i][j] = "."
                                continue
                            else:
                                ys[i][j - 1] ,ys[i][j] = "W" ,"."
                                continue
                        elif xs[i][j] == "N":
                            if xs[i - 1][j + 1] != "W" and xs[i - 2][j] != "S" and xs[i - 1][j - 1] != "E":
                                if xs[i - 1][j] == "X":
                                    ys[i][j] = "."
                                    continue
                                elif xs[i - 1][j] == ".":
                                    ys[i - 1][j] ,ys[i][j] = "N" ,"."
                                    continue
                xs = ys
            else:
                ans.append("NA")
hinan()

### FIXED CODE ###

def hinan():
    ans ,houi ,vector = [] ,[[0 ,1] ,[-1 ,0] ,[0 ,-1] ,[1 ,0] ,[0 ,1] ,[-1 , 0] ,[1 ,0]] ,["E" ,"N" ,"W" ,"S"]
    while True:
        n = raw_input().split(" ")
        if n == ["0" ,"0"]:
            for an in ans:
                print an
            break
        else:
            xs =[[] ,[] ,[]]
            for i in range(int(n[1])):
                n = raw_input()
                xs = [xs[l] + [[[i ,j] for j in range(len(n)) if n[j] != "#"] ,[[[i ,j] ,houi[vector.index(n[j])]] for j in range(len(n)) if n[j] in vector] ,[[i ,j] for j in range(len(n)) if n[j] == "X"]][l] for l in range(3)]
            for time in range(181):
                if len(xs[1]) == 0:
                    ans.append(time)
                    break
                else:
                    for i in xs[1]:
                        where = [l[0] for l in xs[1]]
                        if len([k for k in [[i[0][l] + houi[houi.index(i[1]) - 1 + j][l] for l in range(2)] for j in range(4)] if k in xs[0] and not k in where]) > 0:
                            i[1] = [[k for k in [[i[0][l] + houi[houi.index(i[1]) - 1 + j][l] for l in range(2)] for j in range(4)] if k in xs[0] and not k in where][0][s] - i[0][s] for s in range(2)]
                    go_point = [[i[0][l] + i[1][l] for l in range(2)] for i in xs[1]]
                    for i in range(len(go_point)):
                        if go_point[i] in where or not go_point[i] in xs[0]:
                            go_point[i] = xs[1][i][0]
                        else:
                            if go_point.count(go_point[i]) > 1:
                                for j in range(4):
                                    if xs[1][i] == [[go_point[i][l] + houi[j][l] for l in range(2)] ,houi[j + 2]]:
                                        break
                                    elif [[go_point[i][l] + houi[j][l] for l in range(2)] ,houi[j + 2]] in xs[1]:
                                        go_point[i] = xs[1][i][0]
                                        break
                    else:
                        xs[1] = [k for k in [[go_point[i] ,xs[1][i][1]] for i in range(len(xs[1]))] if not k[0] in xs[2]]
            else:
                ans.append("NA")
hinan()