let get_2_ints () = Scanf.scanf "%d %d " (fun u v -> u,v)
let input_int_array n =
	Array.init n (fun _ -> Scanf.scanf "%d " (fun v -> v))

let digits v =
  let rec f0 p a = if p=0 then a else f0 (p/10) ((p mod 10)::a)
  in f0 v []

let () = 
  let (n,k) = get_2_ints ()
  in let nums = input_int_array k |> Array.to_list
  in
  let f,i,v = ref true,ref n,ref 0
  in while !f do
    let dl = digits !i in
    if not @@ List.exists (fun v -> List.exists ((=) v) nums) dl
    then (
      v:=!i; f:=false
    ) else (
      i:=!i+1
    )
  done;
  !v |> string_of_int |> print_endline