let n, ds = Scanf.(scanf " %d %d" @@ fun n k -> n, Array.(to_list @@ init k @@ fun _ -> scanf " %d" (+) 0))
let rec f i n = if i = 0 then (Printf.printf "%d\n" n; exit 0) else if not @@ List.mem (i mod 10) ds then f (i / 10) n
let _ = for i = n to 10 * n do f i i done