require'prime'
t=[]
Prime.each(1e6){|i|t[i]=1}
(n,x=$_.split
t[m=0]=2
c=$<.take n.to_i
(0..x.to_i).each{|i|(v=t[i])&&v!=1&&(c.each{|j|t[j.to_i+i]|=2};v&1==1&&m<i&&m=i)}
puts m<1?:NA:m
t.map!{|i|i&1==1?1:$,})while gets>?1