let n, k = Scanf.scanf "%d %d" @@ fun a b -> a, b
let fs = Array.make 10 true
let rec f n = n = 0 || fs.(n mod 10) && f (n / 10)
let _ = for _ = 1 to k do Scanf.scanf " %d" @@ fun d -> fs.(d) <- false done; for i = n to 900100 do if f i then (Printf.printf "%d\n" i; exit 0) done