stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

#include <unordered_map>

#define int long long int

#define double long double

#define endl "\n"

#define PI 3.141592653589793238462643383279502884

#define sp(x)   setprecision(x)

#define ceil(a,b)   (a+(b-1))/b

#define LCM(a,b)    (a*b)/__gcd(a,b)

#define all(v)  v.begin(),v.end()

#define alls(s,v)  s.begin(),s.end(),v

#define gena(arr,n,nxt)  generate(arr,arr+n, nxt)

#define genv(v,nxt)  generate(v.begin(),v.end(), nxt)

#define base ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

#define exit return 0;

using namespace std;

const int N=1000000;

bool prime[N];

void sieve()

{

    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<100000000; p++)

    {

        if (prime[p] == true)

        {

            for (int i=p*p; i<100000; i += p)

                prime[i] = false;

        }

    }

}

int power(int x, int y)

{

    int res = 1;

    while (y > 0)

    {

        if (y & 1)

            res = res * x;

        y = y >> 1;

        x = x*x;

    }

    return res;

}

int nxt()

{

    int x;

    cin >> x;

    return x;

}

int findTileCount(int x, int y, int l, int r)

{

    int lcm = (x * y) / __gcd(x, y);

    int countl = (l - 1) / lcm;

    int countr = r / lcm;

    return countr - countl;

}

int32_t main()

{

    base

    int n=nxt(),k=nxt();

    int d[k];

    gena(d,k,nxt);

    int a=n;

    int ans=n;

    int flag=0;

    while(1){

        flag=0;

        a=ans;

        while(a!=0){

            for(int i=0;i<k;i++){

                if(d[i]==a%10){

                    flag=1;

                    break;

                }

            }

            if(flag==1)break;

            a/=10;

        }

        if(flag==0)break;

        ans++;

    }

    cout<<ans<<endl;

    exit

}




// Faster C++ solution for the same problem (measured speedup: 5.24640217965243x):
#include <stdio.h>

#include <math.h>

#define MAX_N 10000

#define MAX_k 9

int N, k;

int D[MAX_k];

int check(int a){

    int i, j, n, m;

n=a;

while(n!=0){

        m = n%10;

        for (j=0; j<k; j++)

            if (m==D[j]) return 1;

            n/=10;

}

    return 0;

}

int main(){

    int i;

    scanf("%d%d", &N, &k);

    for (i=0; i<k; i++)

        scanf("%d", &D[i]);

    i=N;

    while (1)

    {

        if(check(i)==0)break;

        else

        {

            i++;

        }

    }

    printf("%d\n", i);

    return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <iomanip>

#include <cstring>

#include <string>

#include <vector>

#include <queue>

#include <cmath>

#include <stack>

#include <set>

#include <map>

typedef long long ll;

typedef unsigned int uint;

using namespace std;



int main() {

    cin.sync_with_stdio(false);

    cin.tie(0);



    int n, k;

    cin >> n >> k;



    vector<int> kirai;

    for (int i = 0; i < k; i++) {

        int d;

        cin >> d;

        kirai.push_back(d);

    }



    for (int i = 0; i < 100000; i++) {

        int t = i;

        bool valid = true;



        while (t > 0) {

            bool possible = true;

            for (int j = 0; j < kirai.size(); j++) {

                if (t % 10 == kirai[j]) {

                    possible = false;

                }

            }

            if (!possible) valid = false;

            t /= 10;

        }



        if (valid && i >= n) {

            cout << i << endl;

            return 0;

        }

    }

}


// Faster C++ solution for the same problem (measured speedup: 1.1920043374603413x):
#include <algorithm>

#include <iostream>

#include <iomanip>

#include <cstring>

#include <string>

#include <vector>

#include <queue>

#include <cmath>

#include <stack>

#include <set>

#include <map>

typedef long long ll;

typedef unsigned int uint;

using namespace std;



int main() {

    cin.sync_with_stdio(false);

    cin.tie(0);



    int n, k;

    cin >> n >> k;

    int kirai[k];

    for (int i = 0; i < k; i++) {

        cin >> kirai[i];

    }



    for (int i = n; i < 10 * n; i++) {

        int t = i;

        bool valid = true;



        while (t > 0) {

            bool possible = true;

            for (int j = 0; j < k; j++) {

                if (t % 10 == kirai[j]) {

                    possible = false;

                }

            }



            if (!possible) {

                valid = false;

                break;

            }



            t /= 10;

        }



        if (valid) {

            cout << i << endl;

            return 0;

        }

    }

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<cmath>

#include<cstdlib>

#include<queue>

#include<map>

#include<iostream>

#include<algorithm>

#define m(a,b) memset(a,b,sizeof(a));

using namespace std;

const int maxn = 1e4;

const int inf = 1<<30;

typedef long long LL;

int k;

int n;

int main(){

	cin >> n >> k;

	map<int,int>m;

	int a;

	for(int i = 0;i<k;i++){

		cin >> a;

		m[a] = 1;

	}

	for(int i = n;;i++){

		bool ans = true;

		int a = i;

		while(a){

			int b = a%10;

			if(m[b]) {ans = false;break;}

			a/=10;

		}

		if(ans) {n = i;break;}

	}

	cout << n << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.302165822821684x):
#include<cstdio>

#include<cstring>

#include<algorithm>

int n,k,tmp;

bool u[11];

bool check(int t)

{

    while(t)

    {

        if (u[t%10]) return 0;

        t/=10;

    }

    return 1;

}

int main()

{

    scanf("%d%d",&n,&k);

    for(int i=1;i<=k;i++)

    {

        scanf("%d",&tmp);

        u[tmp]=1;

    }

    int cur=n;

    while(!check(cur)) cur++;

    printf("%d",cur);

}
// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;



typedef long long LL;



const int N = 100 + 5;







int a[10];



int check(int x){



	while(x){



		if(a[x % 10]) return 0;//每次获取末位数字判断是否不喜欢



		x /= 10;//更高位



		}



	return 1;//当所有都0喜欢就返回1;



	}



int main(){



	ios::sync_with_stdio(false);



	cin.tie(0);



	



	int n , k , q;



	cin>>n>>k;



	for(int i = 0 ; i < k ; i++){



		cin>>q;



		a[q] = 1;



		}



	while(1){



		if(check(n)){



			cout<<n<<endl;



			break;



			}



		n++;//直到找到



		}



	return 0;



	}

// Faster C++ solution for the same problem (measured speedup: 5.2765031856148505x):
#include<cstdio>

#include<cstring>

#include<algorithm>

int n,k,tmp;

bool u[11];

bool check(int t)

{

    while(t)

    {

        if (u[t%10]) return 0;

        t/=10;

    }

    return 1;

}

int main()

{

    scanf("%d%d",&n,&k);

    for(int i=1;i<=k;i++)

    {

        scanf("%d",&tmp);

        u[tmp]=1;

    }

    int cur=n;

    while(!check(cur)) cur++;

    printf("%d",cur);

}
// Slower C++ solution:
#include<cstdio>

#include<cstdlib>

#include<cmath>

#include<cstring>

#include<string>

#include<iostream>

#include<algorithm>

#include<map>

using namespace std;

int f[10];

bool vis[15];

int main(){

	int n,k,a[15],len;

	scanf("%d%d",&n,&k);

	for(int i=1;i<=k;i++){

		scanf("%d",&a[i]);

		vis[a[i]]=1;

	}

	f[0]=1;

	for(int i=1;i<=8;i++) f[i]=f[i-1]*10;

	for(int i=n;;i++){

		for(int j=1;;j++){

			if(i/f[j]==0){

				len=j;

				break;

			}

		}

		if(len==1){

			if(vis[i]!=1){

				printf("%d\n",i);

				break;

			}

		}

		else if(len==2){

			if(vis[i/10]!=1&&vis[i%10]!=1){

				printf("%d\n",i);

				break;

			}

		}

		else if(len==3){

			if(vis[i%10]!=1&&vis[i/10%10]!=1&&vis[i/100]!=1){

				printf("%d\n",i);

				break;

			}

		}

		else if(len==4){

			if(vis[i%10]!=1&&vis[i/10%10]!=1&&vis[i/100%10]!=1&&vis[i/1000]!=1){

				printf("%d\n",i);

				break;

			}

		}

		else if(len==5){

			if(vis[i%10]!=1&&vis[i/10%10]!=1&&vis[i/100%10]!=1&&vis[i/1000%10]!=1&&vis[i/10000]!=1){

				printf("%d\n",i);

				break;

			}

		}

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.145347410595733x):
#include<cstdio>

#include<cstring>

#include<algorithm>

int n,k,tmp;

bool u[11];

bool check(int t)

{

    while(t)

    {

        if (u[t%10]) return 0;

        t/=10;

    }

    return 1;

}

int main()

{

    scanf("%d%d",&n,&k);

    for(int i=1;i<=k;i++)

    {

        scanf("%d",&tmp);

        u[tmp]=1;

    }

    int cur=n;

    while(!check(cur)) cur++;

    printf("%d",cur);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int arr[10];



bool check(int num) {

    while(num) {

        if(arr[num%10])

            return false;

        num/=10;

    }

    return true;

}



int main()

{

    int n,k;

    int x;

    scanf("%d%d",&n,&k);

    for(int i = 0; i < k; i++) {

        scanf("%d",&x);

        arr[x] = 1;

    }

    while(!check(n)) {

        n++;

    }

    printf("%d",n);

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.142947400379734x):
#include<cstdio>

#include<cstring>

#include<algorithm>

int n,k,tmp;

bool u[11];

bool check(int t)

{

    while(t)

    {

        if (u[t%10]) return 0;

        t/=10;

    }

    return 1;

}

int main()

{

    scanf("%d%d",&n,&k);

    for(int i=1;i<=k;i++)

    {

        scanf("%d",&tmp);

        u[tmp]=1;

    }

    int cur=n;

    while(!check(cur)) cur++;

    printf("%d",cur);

}
// Slower C++ solution:
//### In The Name Of GOD ###



#include <bits/stdc++.h>



using namespace std;



typedef long long ll ;



const int MOD = 1000000007;

const int INF = 30 * 1000 + 20;

const int MAXN = 2600;

const int MLOG = 18;

const int NMAX = 60;



#define int ll

#define pb push_back

#define pp pop_back

#define X first

#define Y second

#define IO ios_base::sync_with_stdio(false);

#define sz(a) (int)(a.size())

#define ct(x) const_cast<const int&>(x)



int32_t main(){

	int n , k;

	cin >> n >> k;

	bool mark[10] ={};

	for(int i = 0; i < k ; i++){

		int a;

		cin >> a;

		mark[a] = true;

	}

	for(int i = n ; i < n*100; i++){

		int a = i;

		while(a > 0 && !mark[a%10])

			a/=10;

		if(a==0){

			cout << i;

			return 0;

		}

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.193420956540264x):
#include<cstdio>

#include<cstring>

#include<algorithm>

int n,k,tmp;

bool u[11];

bool check(int t)

{

    while(t)

    {

        if (u[t%10]) return 0;

        t/=10;

    }

    return 1;

}

int main()

{

    scanf("%d%d",&n,&k);

    for(int i=1;i<=k;i++)

    {

        scanf("%d",&tmp);

        u[tmp]=1;

    }

    int cur=n;

    while(!check(cur)) cur++;

    printf("%d",cur);

}
// Slower C++ solution:
#include <iostream>

#include <cmath>

#include <stdio.h>

#include <algorithm>

#include <string>

#include <vector>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <cstring>



using namespace std;



#define f first

#define s second

#define pb push_back

#define mp make_pair

#define ll long long

#define pii pair < int, int >

#define pll pair < long long, long long>

#define ull unsigned long long

#define vi vector < int >

#define vll vector < long long >

#define sz(a) (int)a.size()

#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)

#define all(a) a.begin(), a.end()

#define sqr(x) ((x) * (x))

#define fname "searching"



const int inf = (int)1e9;

const ll INF = (ll)1e18;

const double eps = 1e-9;

const double pi = acos(-1.0);

const int mod = (int)1e9 + 7;



int n, k;

bool d[10];



int solve(){

    for(int i = n; i < 1000000; ++i){

        string s = to_string(i);

        bool ok = 1;

        for(int j = 0; j < sz(s); ++j){

            if(d[s[j] - '0']){

                ok = 0;

                break;

            }

        }

        if(ok) return i;

    }

    return n;

}



int main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cin >> n >> k;

    for(int i = 0, x; i < k; ++i){

        cin >> x;

        d[x] = 1;

    }

    

    cout << solve() << "\n";



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.491315121484984x):
#include<cstdio>

#include<cstring>

#include<algorithm>

int n,k,tmp;

bool u[11];

bool check(int t)

{

    while(t)

    {

        if (u[t%10]) return 0;

        t/=10;

    }

    return 1;

}

int main()

{

    scanf("%d%d",&n,&k);

    for(int i=1;i<=k;i++)

    {

        scanf("%d",&tmp);

        u[tmp]=1;

    }

    int cur=n;

    while(!check(cur)) cur++;

    printf("%d",cur);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

set< int > se;



bool check( int n ) {

    while( n ) {

        if( se.count(n%10) ) return true;

        n /= 10;

    } 

    return false;

}



int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int n, d, temp;

    cin >> n >> d;

    for( int i = 0; i < d; i++ ) {

        cin >> temp;

        se.insert( temp );

    }

    string ans;

    while( check(n) ) n++;

    cout << n << '\n';

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.333691106620831x):
#include<cstdio>

#include<cstring>

#include<algorithm>

int n,k,tmp;

bool u[11];

bool check(int t)

{

    while(t)

    {

        if (u[t%10]) return 0;

        t/=10;

    }

    return 1;

}

int main()

{

    scanf("%d%d",&n,&k);

    for(int i=1;i<=k;i++)

    {

        scanf("%d",&tmp);

        u[tmp]=1;

    }

    int cur=n;

    while(!check(cur)) cur++;

    printf("%d",cur);

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int dis[10];



bool likes(int n){

    while(n){

        if(dis[n%10] == true) return false;

        n /= 10;

    }

    return true;

}



int main(){

    int n, k, x;

    cin >> n >> k;

    for(int i = 0; i < k; i++){

        cin >> x;

        dis[x] = true;

    }

    while(likes(n) == false) n++;

    cout << n << '\n';

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.201875163313127x):
#include<cstdio>

#include<cstring>

#include<algorithm>

int n,k,tmp;

bool u[11];

bool check(int t)

{

    while(t)

    {

        if (u[t%10]) return 0;

        t/=10;

    }

    return 1;

}

int main()

{

    scanf("%d%d",&n,&k);

    for(int i=1;i<=k;i++)

    {

        scanf("%d",&tmp);

        u[tmp]=1;

    }

    int cur=n;

    while(!check(cur)) cur++;

    printf("%d",cur);

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;

int k[15],a[101],flag,k1,vis[101];

int main(){

	int n,k2;

	cin>>n>>k2;

	for(int i=0;i<k2;i++){

		cin>>k[i];

		vis[k[i]]=true;

	}

	for(int m=1;m<=100000;m++){

		k1=0,flag=0;

		int i=m;

		while(i>0){

			a[k1++]=i%10;

			i/=10;

		}

		for(int j=0;j<k1;j++){

			if(vis[a[j]]){

			flag=1;

			continue;	

			} 

		}

		if(flag==0&&m>=n){

		cout<<m<<endl;	

		break;

		} 

		

	}

	

}

// Faster C++ solution for the same problem (measured speedup: 1.1587164224490003x):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;

typedef pair<int, pii> pipii;

typedef pair<pii, pii> piipii;



#define mp make_pair

#define fi first

#define se second

#define all(a) (a).begin(), (a).end()

#define sz(a) (int)(a).size()

#define eb emplace_back



char s[105];

bool vis[10];

int main(){

    int n, k, a;

    scanf("%d%d", &n, &k);

    for(int i=1;i<=k;i++) scanf("%d", &a), vis[a] = 1;

    for(int i=n;;i++){

        int x = i;

        bool ok = 1;

        while(x > 0){

            if(vis[x%10]){

                ok = 0;

                break;

            }

            x/=10;

        }

        if(ok){

            printf("%d\n", i);

            return 0;

        }

    }

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;

int k[15],a[101],flag,k1,vis[101];

int main(){

	int n,k2;

	cin>>n>>k2;

	for(int i=0;i<k2;i++){

		cin>>k[i];

		vis[k[i]]=true;

	}

	for(int m=1;m<=100000;m++){

		k1=0,flag=0;

		int i=m;

		while(i>0){

			a[k1++]=i%10;

			i/=10;

		}

		for(int j=0;j<k1;j++){

			if(vis[a[j]]){

			flag=1;

			continue;	

			} 

		}

		if(flag==0&&m>=n){

		cout<<m<<endl;	

		break;

		} 

		

	}

	

}

// Faster C++ solution for the same problem (measured speedup: 1.083221910192265x):
#include<bits/stdc++.h>

using namespace std;



int main()

{

    int n;

    cin>> n;



    set<int> st{0,1,2,3,4,5,6,7,8,9};



    int k;

    cin>> k;



    while(k--)

    {

        int input;

        cin>> input;

        st.erase(input);

    }



    long int ans = 0;

    while(1)

    {

        bool check = true;

        long int temp = n;

        vector<int>vec;

        while(temp)

        {

            vec.push_back(temp % 10);

            temp/= 10;

        }



        for(int i = 0; i < vec.size(); i++)

        {

            if(st.find(vec[i]) == st.end())

            {

                check = false;

                break;

            }

        }



        if(check)

        {

            ans = n;

            break;

        }

        else

            n++;

    }



    cout<< ans;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;

int k[15],a[101],flag,k1,vis[101];

int main(){

	int n,k2;

	cin>>n>>k2;

	for(int i=0;i<k2;i++){

		cin>>k[i];

		vis[k[i]]=true;

	}

	for(int m=1;m<=100000;m++){

		k1=0,flag=0;

		int i=m;

		while(i>0){

			a[k1++]=i%10;

			i/=10;

		}

		for(int j=0;j<k1;j++){

			if(vis[a[j]]){

			flag=1;

			continue;	

			} 

		}

		if(flag==0&&m>=n){

		cout<<m<<endl;	

		break;

		} 

		

	}

	

}

// Faster C++ solution for the same problem (measured speedup: 1.119956705808837x):
//BISMILLAHIR RAHMANIR RAHIM

//SOTO MEAW

//SOTO SONDESH

#include<bits/stdc++.h>



#define ls ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ll long long

#define __ <<" "<<

#define loop(m,n) for(m=0;m<n;m++)

#define rloop(m,n) for(m=n-1;m>=0;m--)

#define case(z) "Case " << z++ << ": "

#define yes cout << "YES" << endl

#define no cout << "NO" << endl

#define quit return 0



using namespace std;



bool isprime(int n)

{

    for (int i = 2; i <= n/2; i++)

    {

        if (n % i == 0)

            return false;

    }

    return true;

}



void showmyDS(set<int> ds)

{

    set<int> ::iterator it;

    for (it=ds.begin();it!=ds.end();it++)

    {

        cout << *it << endl ;

    }

    cout << endl;

}

int main()

{

    ls

    //freopen("in.txt","r",stdin);

    //freopen("out.txt","w",stdout);

    //int t,l=1;cin>>t;while(t>0){

        vector<char>s;

        int j;

        string s1;

        cin>>s1;

        loop(j,s1.size()) s.push_back(s1[j]);

        int n,i,c=0;

        cin>>n;

        char a[n];

        int p,index[255];

        memset(index,0,sizeof(index));

        loop(i,n)

        {

            cin>>a[i];

            p=(int)a[i];

            index[p]=1;

        }

        loop(i,s.size())

        {

            p=(int)s[i];

            if(c==1)

                p=48;

again:

            if(index[p]==1 && p==57)

            {

                if(i!=0)

                    p=48;

                else

                    p=49;

                s.push_back('0');

                c=1;

            }

            if(index[p]==1)

            {

                p++;

                c=1;

                goto again;

            }

            else

            {

                cout<<(char)p;

            }

        }

        cout<<endl;

    //t--;}



    quit;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){

	int n,k;

	cin>>n>>k;

	int i,j;

	bool d[10]={};

	for(i=0;i<k;i++){

		cin>>j;

		d[j]=true;

	}

	string s;

	bool f;

	char c[10];

	for(i=0;i<10;i++) c[i]='0'+i;

	for(i=n;i<n*100;i++){

		stringstream ss;

		ss<<i;

		s=ss.str();

		f=true;

		for(j=0;j<10;j++){

			if(d[j]&&s.find(c[j])!=-1){

				f=false;

				break;

			}

		}

		if(f){

			cout<<i<<endl;

			break;

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2317942617998798x):
#include <iostream>

#include <string.h>

#include <bits/stdc++.h>



using namespace std;



int main()

{

    int n,a[20]={0},b[15]={0},j,i,o=0;

    int k=0,l=0,flag=0,e=0,f;

    char c[6]={0};

    scanf("%s%d",c,&n);

    for(i=0;i<n;i++)

    {

        scanf("%d",&a[i]);

    }



    for(i=0;i<10;i++)

    {

        if(i==a[k]&&k<n-1) k++;

        else if(i==a[n-1]);

        else b[l++]=i;

    }

    f=strlen(c);

    for(i=0;i<f;i++)

    {

        c[i]-='0';

    }

    for(i=f-1;i>=0;i--)

    {

        flag=0;

        o=0;

        for(j=0; j<l; j++)

        {

            if(c[i]<b[j])

            {

                c[i]=b[j];

                flag=1;

                break;

            }

            else if(c[i]==b[j])

            {

                c[i]=b[j];

                o=1;

                break;

            }

        }

        if(flag==0&&i>0&&o==0)

        {

            for(j=i;j<f;j++)

            {

                c[j]=b[0];

            }

            c[i-1]++;

        }

        else if(flag==0&&b[0]!=0&&o==0) e=b[0];

        else if(flag==0&&b[0]==0&&o==0) e=b[1];

        if(flag==1||e!=0)

        {

            for(j=i+1;j<f;j++)

            {

                c[j]=b[0];

            }

            if(e!=0) c[0]=b[0];

        }

    }



    if(e!=0)

    printf("%d",e);

    for(i=0;i<f;i++)

    {

        printf("%d",c[i]);

    }

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

bool ng[10];

signed main(){

	int n,k;

	cin>>n>>k;

	for(int i=0;i<k;i++){

		int d;cin>>d;

		ng[d]=true;

	}

	for(;;n++){

		stringstream ss;

		ss<<n;

		string s=ss.str();

		bool ok=true;

		for(int j=0;j<s.size();j++) if(ng[s[j]-'0']) ok=false;

		if(ok){

			cout<<n<<endl;

			return 0;

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2216385096868831x):
#include<bits/stdc++.h>

using namespace std;

int bit(int x){

	int r=0;

	while(x){

		r|=1<<(x%10);

		x/=10;

	}

	return r;

}

int main(){

	int n,k,b=0;

	scanf("%d %d",&n,&k);

	while(k--){

		int x;

		scanf("%d",&x);

		b|=1<<x;

	}

	while(bit(n)&b) n++;

	printf("%d\n",n);

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

using namespace std;



int p[10];

int ans=100000;

int n,k;

void dfs(int sum,int q){

	//printf("%d %d\n",sum,q);

	if(sum>=n){ans=min(ans,sum);return;}

	if(q>10000)return;

	for(int i=0;i<10;i++){

		if(!p[i]){/*printf("%d\n",i);*/dfs(sum+q*i,q*10);}

	}

}

int main(){

	scanf("%d%d",&n,&k);

	for(int i=0;i<k;i++){

		int c;

		scanf("%d",&c);

		p[c]=1;

	}

	dfs(0,1);

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1032733149452938x):
#include <bits/stdc++.h>

#include<ext/pb_ds/hash_policy.hpp>

#include<ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

using namespace std;

typedef long long LL;

typedef unsigned long long uLL;

struct custom_hash {

    static uint64_t splitmix64(uint64_t x) {

        x += 0x9e3779b97f4a7c15;

        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;

        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;

        return x ^ (x >> 31);

    }

    size_t operator()(uint64_t x) const {

        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();

        return splitmix64(x + FIXED_RANDOM);

    }

};

LL z = 1;

int read(){

	int x, f = 1;

	char ch;

	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;

	x = ch - '0';

	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;

	return x * f;

}

int ksm(int a, int b, int p){

	int s = 1;

	while(b){

		if(b & 1) s = z * s * a % p;

		a = z * a * a % p;

		b >>= 1;

	}

	return s;

}

int v[15], a[15];

char s[15];

int pd(int x){

	int i;

	while(x){

		i = x % 10;

		x /= 10;

		if(v[i]) return 0;

	}

	return 1;

}

int main(){

	int i, j, t, n, m, flag = 0;

	n = read();

	m = read();

	for(i = 1; i <= m; i++){

		j = read();

		v[j] = 1;

	}

	for(i = n; i <= 100000; i++){

		if(pd(i)){

			printf("%d", i);

			return 0;

		}

	}

	return 0;

}