def g;gets.split.map &:to_i;end
def r c;c.map{|i|i.reverse}.transpose;end
while(n,m=g)[0]>0
v=(1..n).map{g}
c=(1..m).map{g}
t=[c,s=r(c),u=r(s),r(u)]
w=0..n-m
d=[*0..m-1]
e=d.product d
puts (a=w.find{|i|m=w.map{|j|j+t.map{|k|e.all?{|y,x|k[y][x]<0||v[i+y][j+x]==k[y][x]}?k[0].index{|l|l>=0}:n}.min}.min;m<n})?[m+1,a+1]*" ":"NA"
end