while(w,h=gets.split.map &:to_i)[0]>0
a=[]
m=(0...h).map{|i|l=gets;(0...l.size).map{|j|l[j]=~/[WSEN]/&&a<<[j,i,"WSEN".index($&)]};l}
t=0
while a[0]&&181>t+=1
n=a.map{|i,j,d|[[i,j-1,3],[i-1,j,0],[i,j+1,1],[i+1,j,2]].rotate(d).find{|e,f|m[f][e]!=?#&&a.all?{|k,l|k!=e||l!=f}}}
a=n.map.with_index{|l,k|i,j,d=l;i&&n.all?{|e,f,g|i!=e||j!=f||d<=g}?l:a[k]}
a.reject!{|i,j,k|m[j][i]==?X}
end
puts t>180?:NA:t
end