#include<bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1061109567;
const ll LINF = 4557430888798830399ll;

/*---*/

int d[15];

void TestCase() {
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= k; ++i)
        scanf("%d", &d[i]);
    for(int i = n;; ++i) {
        int x = i;
        int suc = 1;
        while(x && suc) {
            int di = x % 10;
            for(int j = 1; j <= k; ++j) {
                if(di == d[j]) {
                    suc = 0;
                    break;
                }
            }
            x /= 10;
        }
        if(suc) {
            printf("%d\n", i);
            return;
        }
    }
}

int main() {
#ifdef KisekiPurin
    freopen("KisekiPurin.in", "r", stdin);
    //freopen("KisekiPurin.out", "w", stdout);
#endif // KisekiPurin
    //InitCase();
    int t = 1;
    //scanf("%d", &t);
    for(int i = 1; i <= t; ++i) {
        //printf("Case #%d:", i);
        TestCase();
    }
    return 0;
}
