#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl "\n";
#define MAX 1000000+9   //Maximum array size;

void fast() {
    cin.tie(0);
    cin.sync_with_stdio(0);
}

int main() {
    fast();
    int num, q;
    cin >> num >> q;
    int c[q];
    string s = "";
bool valid=true;
    for (int i = 0; i < q; ++i) {
        cin >> c[i];
    }
    for (int l = 0; l < 10; ++l) {
        for (int i = 0; i < q; ++i) {
            if (l == c[i]) {
                break;
            } else {
                if (i == q - 1) {
                    s += to_string(l);
                }
            }
        }
    }
    for (int j = num; j <= num * 10; ++j) {
        string b = to_string(j);
        int counter = 0;
        for (int i = 0; i < b.size(); ++i) {
            for (int k = 0; k < s.size(); ++k) {
                if (b[i] == s[k]) {
                    counter++;
                    break;
                }
            }
        }
        if (counter == b.size()) {
			valid=false;
            cout << b;
            break;
        }
    }
if(valid){
cout<<0;
}
}