open Batteries
let inf = 1010101010
let n, k = Scanf.scanf "%d %d" (fun x y -> x, y)
let dislikes = List.init k (fun _ -> Scanf.scanf " %c" (fun x -> x))

let ans =
  List.init 100001 (fun p ->
    if p < n then inf
    else
      let res =
        p |> string_of_int |> String.to_list
        |> List.exists (fun d -> List.mem d dislikes)
      in
      if res then inf else p
  ) |> List.fold_left min inf;;

Printf.printf "%d\n" ans
