#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int N, K;
vector<int> D;

void dfs(int n) {
    bool flag = false;
    int tmp = n;
    while (tmp > 0) {
        for (int i = 0; i < K; i++) {
            if (tmp % 10 == D[i]) {
                flag = true;
                break;
            }
        }
        if (flag == true) break;
        tmp /= 10;
    }
    if (flag == true) dfs(n + 1);
    if (flag == false) cout << n << endl;
}

int main() {
    cin >> N >> K;
    for (int i = 0; i < K; i++) {
        int d;
        cin >> d;
        D.push_back(d);
    }
    dfs(N);
    return 0;
}
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    int N,K;
    cin >> N >> K;
    set<int> D;
    REP(_,K) {
        int d;
        cin >> d;
        D.insert(d);
    }

    FOR(val,N,100000) {
        string s = to_string(val);
        bool ok = true;
        for(const auto &it: s) if(D.count(((int)it-'0'))) ok = false;
        if(!ok) continue;
        cout << val << endl;
        return;
    }
}

int main() {
    solve();
    return 0;
}