let n, k = Scanf.scanf "%d %d\n" (fun a b -> a, b)
let ds = Array.init k (fun _ -> Scanf.scanf "%c " (fun x -> x))

let rec solve p =
  if (Array.fold_left (fun pre c ->
      pre || String.contains (string_of_int p) c) false ds)
  then solve (p + 1)
  else p

let () = solve n |> Printf.printf "%d\n"