Scanf.scanf "%d %d" (fun n k ->
    let d = Array.make 10 false in
    for i = 1 to k do
        Scanf.scanf " %d" (fun j -> d.(j) <- true)
    done;

    let check k =
        let s = string_of_int k in
        let sn = String.length s in
        let rec loop i =
            if i = sn then true else
                if d.(int_of_char s.[i] - 48) then false else loop (i + 1)
        in
        loop 0
    in

    let rec loop i =
        if check i then Printf.printf "%d\n" i else loop (i + 1)
    in
    loop n
)