open Batteries
open Printf
let () =
  let n,k = Scanf.scanf "%d %d " (fun a b -> a,b) in
  let d_l = Array.to_list @@ Array.init k (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let rec digits base n res =
    if n = 0 then res 
    else digits base (n/base) ((n mod base)::res)
  in

  let intersection xs ys =
    List.fold_left (fun a b -> if List.mem b ys then (b::a) else a) [] xs
  in

  let rec aux n =
    let i_l = digits 10 n [] in
    if intersection i_l d_l = [] then
      n
    else aux (n+1)
  in

  Printf.printf "%d\n" @@
  aux n
