Problem:
Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

1 ≦ N < 10000

1 ≦ K < 10

0 ≦ D_1 < D_2 < … < D_K≦9

\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

Input

The input is given from Standard Input in the following format:

N K
D_1 D_2 … D_K

Output

Print the amount of money that Iroha will hand to the cashier.

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Sample Input 2

9999 1
0

Sample Output 2

9999

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
fn main() {
    proconio::input! {
        n: usize,
        k: usize,
        ds: [usize; k],
    }
    let mut enable_numbers = vec![true; 10];
    for d in ds {
        enable_numbers[d] = false;
    }
    let enable_numbers = enable_numbers
        .into_iter()
        .enumerate()
        .filter(|(_i, b)| *b)
        .map(|(i, _b)| i)
        .collect::<Vec<_>>();
    let nis = {
        let mut n = n;
        let mut tmp = vec![];
        while n != 0 {
            let m = n % 10;
            tmp.push(m);
            n /= 10;
        }
        tmp.reverse();
        tmp
    };
    let mut ans = 0;
    if enable_numbers
        .iter()
        .all(|&enable_number| enable_number < nis[0])
    {
        ans = if enable_numbers[0] == 0 {
            enable_numbers[1]
        } else {
            enable_numbers[0]
        };
        while ans < n {
            ans = ans * 10 + enable_numbers[0];
        }
        println!("{}", ans);
        return;
    }
    let mut ordering = std::cmp::Ordering::Less;
    for ni in nis {
        match ordering {
            std::cmp::Ordering::Less | std::cmp::Ordering::Equal => {
                let a = enable_numbers
                    .iter()
                    .find(|&&enable_number| enable_number >= ni)
                    .unwrap();
                ans = ans * 10 + a;
                if *a == ni {
                    ordering = std::cmp::Ordering::Equal;
                } else {
                    ordering = std::cmp::Ordering::Greater;
                }
            }
            std::cmp::Ordering::Greater => {
                let a = enable_numbers[0];
                ans = ans * 10 + a;
            }
        }
    }
    println!("{}", ans);
}
*/

fn main() {
    let exe = "/tmp/binE2345234";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";