#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, K, D[10];

bool check(ll x){
    while(x > 0){
        ll d = x % 10;
        REP(i, K){
            if(d == D[i]) return false;
        }
        x /= 10;
    }
    return true;
}

signed main(){
    cin >> N >> K;
    REP(i, K) cin >> D[i];
    ll ans = N;
    while(true){
        if(check(ans)) break;
        ans++;
    }
    PRINT(ans);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> D(10, 0);
    for(int i=0; i<K; i++) {
        int a;
        cin >> a;
        D[a] = 1;
    }

    for(int i=N; i<=100000; i++) {
        int num = i;
        bool flg = true;
        while(num) {
            int x = num % 10;
            if (D[x] == 1) {
                flg = false;
                break;
            }
            num /= 10;
        }
        if(flg && i>= N) {
            cout << i << endl;
            return 0;
        }
    }
}