while(h=gets.split[1].to_i)>u=t=0
a=[]
m=(0...h).map{|i|u=0;gets.chars.map{|c|(d="WSEN".index c)&&a<<[u,i,d];u+=1};$_}
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.zip(a).map{|l,k|i,j,d=l;l ?n.all?{|e,f,g|i!=e||j!=f||d<=g}?l:k[0,2]+[d]:k}.reject{|i,j|m[j][i]==?X}
end
puts t>180?:NA:t
end