import Control.Monad
import Control.Applicative
import System.Random
import Data.Array

solve ms max ns = filter iter ms
  where
    memo = listArray (0, max) $ map iter [0..max]

    iter 0 = True
    iter i = any id $ map (\n -> if i < n then False else memo ! (i - n)) ns

primes = 2:3:[x|i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x] where
  isPrime n = null [i|i<-takeWhile (\x -> x*x <= n) primes, rem n i == 0]

primesBRev max = reverse $ takeWhile (<= max) primes

v0202 max ns = let res = solve (primesBRev max) max ns in
               if res == [] then "NA"
                            else show $ head res

while :: (Monad m) => (a -> Bool) -> m a -> m [a]
while p f = do
  a <- f
  if p a then liftM (a :) (while p f) else return []

routine :: IO (Int, Int, [Int])
routine = do
  [n, max] <- map read . words <$> getLine
  if (n, max) /= (0, 0)
    then do costs <- replicateM n readLn
            return (n, max, costs)
    else return (0, 0, [])

main = do
  inps <- while (\(_,_,c) -> c /= []) routine
  mapM_ (\(n, max, costs) -> putStrLn $ v0202 max costs) inps