open Scanf

let rec primes last =
  if last < 2 then []
  else if last = 2 then [2]
  else if last mod 2 = 0 then primes (last - 1)
  else
    let index n = (n - 3) / 2 in
    let value i = 2 * i + 3 in
    let last_index = index last in
    let sieve = Array.make (last_index + 1) true in
    let rec mark i step =
      if i < Array.length sieve then begin
        sieve.(i) <- false;
        mark (i + step) step
      end
      else () in
    let primes = ref [2] in
    for i = 0 to last_index do
      if sieve.(i) then begin
        primes := (value i) :: !primes;
        mark (2 * i * i + 6 * i + 3) (value i)
      end
    done;
    !primes

let rec matches budget prices =
  if budget = 0 then true
  else
    match prices with
      | [] -> false
      | price :: prices when price > budget -> false
      | price :: prices' ->
         let budget = budget - price in
         matches budget prices || matches budget prices'

let read_lines n =
  let rec read_lines n acc =
    if n = 0 then List.rev acc
    else read_lines (pred n) ((read_line ())::acc) in
  read_lines n []

let rec solve () =
  sscanf
    (read_line ()) "%d %d"
    (fun n budget ->
     if n = 0 && budget = 0 then ()
     else
       let prices =
         List.map int_of_string (read_lines n)
         |> List.sort (fun (a : int) b -> compare b a) in
       let result =
         try
           List.find (fun prime -> matches prime prices) (primes budget)
           |> string_of_int
         with Not_found -> "N/A" in
       print_endline result;
       solve ())

let () = solve ()