//
//  main.swift
//  Atcoder
//
//  Created by Louis Joe Shen on 2020/7/17.
//  Copyright © 2020 Louise Joe Shen. All rights reserved.
//

import Foundation

var input = readLine()
var input2 = readLine()
var inputs = input!.components(separatedBy: " ")
var inputs2 = input2!.components(separatedBy: " ")

var N = Int(inputs[0])!
var K = Int(inputs[1])!

var D : [Int] = [Int]()

for i in 0 ..< K {
    D.append(Int(inputs2[i])!)
}

for i in N ... 666666 {
    if(isLike(number: i)){
        print(i)
        break;
    }
}
func isLike(number: Int) -> Bool {
    let delta = String(number)
    for c in delta {
        for dig in D {
            if(Int(String(c))! == dig){
                return false
            }
        }
    }
    return true;
}
