#include <iostream>

#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>

using namespace std;
//const char a[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
// input - given string
// You need to update in the given string itself i.e. in input. No need to return or print.


int solver() {
    // Write your code here
    int n;
    cin>>n;

    int l;
    cin>>l;
    //vector<int> my;
    int freq[10];
    for(int i=0;i<=9;i++)
    {
        freq[i]=0;
    }
    for(int i=0;i<l;i++)
    {
        int x;
        cin>>x;
      //  my[i]=x;
        freq[x]=1;
    }
    //cout<<my[0];
    for(int j=n;j<100000;j++)
    {
        int num=j;
        bool k=true;
        while(num>0)
        {
            int m=num%10;
            if(freq[m]==1)
            {
                k=false;
                break;
            }
            num=num/10;
        }
        if(k)
        {
            return j;
        }


    }
    return 0;























}


int main() {
    int n=1;
    //cin>>n;
    while(n--)
    {
        cout<<solver();
    }
}

#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n, K;
    cin >> n >> K;
    vector<int> bad(10, false);
    for (int i = 0; i < K; ++i) {
        int x;
        cin >> x;
        bad[x] = true;
    }

    int mn = 10;
    for (int k = 0; k < 10; ++k) {
        if (!bad[k]) {
            mn = k;
            break;
        }
    }

    string s = to_string(n);
    n = s.length();
    for (int i = 0; i < n; ++i) {
        int d = s[i] - '0';
        if (bad[d]) {
            while (i >= 0) {
                bool done = false;
                d = s[i] - '0';
                for (int j = d + 1; j < 10; ++j) {
                    if (!bad[j]) {
                        s[i] = (char) ('0' + j);
                        for (int k = i + 1; k < n; ++k) {
                            s[k] = (char)('0' + mn);
                        }
                        done = true;
                        break;
                    }
                }
                if (done) {
                    break;
                }
                --i;
            }

            if (i < 0) {
                for (int j = 1; j < 10; ++j) {
                    if (!bad[j]) {
                        s = string(1, (char)('0' + j));
                        break;
                    }
                }
                s += string(n, (char)('0' + mn));
            }

            break;
        }
    }


    cout << s << '\n';


    return 0;
}