#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define ld long double
typedef pair<ll,ll> pii;
const int maxn=100005;
const int mod=1e9+7;
int n,k;
int ban[maxn];
bool chk(int x)
{
    int tp=x;
    while(x)
    {
        if(ban[x%10])
            return false;
        x/=10;
    }
    cout<<tp<<endl;
    return true;
}
int main()
{
    #ifdef local
    freopen("in.txt","r",stdin);
    #endif // local
    IOS;
    cin>>n>>k;
    for(int i=1;i<=k;i++)
    {
        int x;
        cin>>x;
        ban[x]=1;
    }
    for(int i=n;;i++)
        if(chk(i))
            return 0;
}