stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<cstdio>

#include<algorithm>

#include<iostream>

#include<cstring>

using namespace std;

int n,k,c,t;

int a[10];

bool y(int x)

{

    for(;x;x/=10)

    if(a[x%10])

        return false;

    return true;

}

int main()

{

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

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

      {

         scanf("%d",&t);

         a[t]=1;

      }

    while(!y(n))

    {

        n++;



    }

    cout<<n<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

bool flag[10];

bool check(int x){

	char s[100];

	sprintf(s,"%d",x);

	for(int i=0;s[i];i++)

		if(flag[s[i]-'0'])

			return false;

	return true;

}

int main(){

	int n,m;

	while(~scanf("%d%d",&n,&m)){

		int temp;

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

			scanf("%d",&temp);

			flag[temp]=1;

		}

		int ans;

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

			if(check(i)){

				ans=i;

				break;

			}

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

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

int num[100005];

bool judge(int n)

{

	while(n)

	{

		int b=n%10;

		if(num[b])

		{

		  	return false;

		}

	   n/=10;	  

	}

	return true;

}

int main()

{

	int N,K;

	while(scanf("%d%d",&N,&K)!=EOF)

	{

		memset(num,0,sizeof(num));

		int k;

		for(int i=0;i<K;i++)

		{

			scanf("%d",&k);

			  num[k]=1;

		}

		for(int i=N;;i++)

		{

			if(judge(i))

			{

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

				break;

			}

		}

	}

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

bool flag[10];

bool check(int x){

	char s[100];

	sprintf(s,"%d",x);

	for(int i=0;s[i];i++)

		if(flag[s[i]-'0'])

			return false;

	return true;

}

int main(){

	int n,m;

	while(~scanf("%d%d",&n,&m)){

		int temp;

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

			scanf("%d",&temp);

			flag[temp]=1;

		}

		int ans;

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

			if(check(i)){

				ans=i;

				break;

			}

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

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main()

{

  int n, k; cin >> n >> k;

  vector<char> d;

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

	char t; cin >> t;

	d.push_back(t);

  }

  while (true) {

	bool flag = true;

	string s = to_string(n);

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

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

		if (s[i] == d[j]) {

		  flag = false;

		}

	  }

	}

	if (flag) {

	  cout << n << endl;

	  return 0;

	}

	n++;

  }

  return 0;

}




// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);  

	

	int n, k;

	cin >> n >> k;

	vector<int> num(10);

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

		int x;

		cin >> x;

		num[x]++;

	}

	while(true) {

		int m = n;

		bool ok = true;

		while(m > 0) {

			if(num[m % 10]) ok = false;

			m /= 10;

		}

		if(ok) {

			cout << n << endl;

			return 0;

		}

		n++;

	}

	return 0;	

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<string.h>

using namespace std;



int main(){ 

  int n, k;

  cin >> n >> k;

  int nums[10]{};

  

  while(k--){

    int index;

    cin >> index;

    nums[index]++;

  }



  bool found = false;

  int pay = n;

    

  while(!found){

	string money =  to_string(pay);

    bool have = true;

    for(int i=0;i<money.length();++i){

    	char c = money[i];

      	int digit = c -'0';

      	if(nums[digit]==1){

        	have = false;

          	break;

        }

    }

    if(have) found = true;

    else pay++;

  }

  cout << pay << endl;

  

  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



int digits[10];



bool works(int x){

	bool is = true;

	while(x){

		int d = x%10;

		if(digits[d]==1){

			is = false;

			break;

		}

		x/=10;

	}

	return is;

}



int main(){

	int n,k;

	cin >> n >> k;



	while(k--){

		int c;

		cin >> c;

		digits[c] = 1;

		//cout << "se marco el digito " << c << endl;

	}

	bool found = false;

	while(!found){

		if(works(n))break;

		else{

			n++;

		}

	}

	cout << n << endl;



	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <climits>

#include <algorithm>

#include <cmath>

#include <map>

#include <set>

#include <string>

#include <bitset>

#include <utility>

#include <numeric>

#include <queue>

#include <stack>



using ll = long long;

using namespace std;



constexpr int MOD = 1e9 + 7;

constexpr ll MOD_LL = ll(1e9 + 7);



int main(void) {

	int n, k;

	cin >> n >> k;

	

	vector<int> ng(10, 0);

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

		int a;

		cin >> a;

		ng[a] = 1;

	}

	

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

		int tmp = i;

		vector<int> digits;

		

		while( tmp ) {

			digits.push_back(tmp % 10);

			tmp /= 10;

		}

		

		bool ok = true;

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

			if( ng[digits[j]] == 1 ) {

				ok = false;

				break;

			}

		}

		

		if( ok && n <= i ) {

			cout << i << endl;

			return 0;

		}

	}

	

	return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <climits>

#include <algorithm>

#include <cmath>

#include <map>

#include <set>

#include <string>

#include <bitset>

#include <utility>

#include <numeric>

#include <queue>

#include <stack>



using ll = long long;

using namespace std;



constexpr int MOD = 1e9 + 7;

constexpr ll MOD_LL = ll(1e9 + 7);



int main(void) {

	int n, k;

	cin >> n >> k;

	

	vector<int> ng(10, 0);

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

		int a;

		cin >> a;

		ng[a] = 1;

	}

	

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

		int tmp = i;

		bool ok = true;

		

		while( tmp ) {

			if( ng[tmp % 10] == 1 ) {

				ok = false;

				break;

			}

			

			tmp /= 10;

		}

		

		if( ok && n <= i ) {

			cout << i << endl;

			break;

		}

	}

	

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>



using namespace std;



int main()

{

	int n, k;

	cin >> n >> k;

	vector<int> d(k);

	for(auto &ref : d){

		cin >> ref;

	}



	while(true){

		string str_n = to_string(n);

		bool find_f = false;

		for(auto i : d){

			if(str_n.find(to_string(i)) != -1){//嫌いな数字が含まれていた場合

				find_f = true;

			}

		}

		if(!find_f){//嫌いな数字が一つも含まれていなかった場合

			break;//ループを抜けて出力

		}

		n++;

	}

	cout << n;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>



using namespace std;



int main()

{

	int n, k;

	cin >> n >> k;

	vector<int> d(k);

	for(auto &ref : d){

		cin >> ref;

	}



	while(true){

		string str_n = to_string(n);

		bool find_f = false;

		for(auto i : d){

			if(str_n.find(to_string(i)) != -1){//嫌いな数字が含まれていた場合

				find_f = true;

				break;

			}

		}

		if(!find_f){//嫌いな数字が一つも含まれていなかった場合

			break;//ループを抜けて出力

		}

		n++;

	}

	cout << n;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int k, n;

bool disliked[125];

 

bool cek(int x) {

    while(x > 0) {

        int now = x % 10;

        if(disliked[now]) return false;

        x /= 10;

    }

	return true;

}

 

int main() {

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

	for(int i = 0 ; i < 123 ; i++) disliked[i] = false;

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

        int qwe;

        scanf("%d", &qwe);

        disliked[qwe] = true;

    }

 

	for(int i = n ; i < INT_MAX-1 ; i++) {

		if(cek(i)) {

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

			return 0;

		}

	}

 

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

int n,k;

char a[15];

bool num[15];



bool check(int a) {

    int cnt=0;

    while (a) {

        if (!num[a%10]) return false;

        a/=10;

    }

    return true;

}



int main() {

    memset(num,1,sizeof(num));

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

    int tmp;

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

        scanf("%d",&tmp);

        num[tmp]=0;

    }

    int ans=n;

    while (!check(ans)) ans++;

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int gl(int x)

{

	using namespace std;

	int leng=0;

	while(x)

	{

		x/=10;

		leng++;

	}

	return leng;

}

int main()

{

	int n, k;

	cin>>n>>k;

	int no[10] = {0};

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

		int t;

		cin>>t;

		no[t] = 1;

	}

	int nown = n;

	while(1){

        int len = gl(nown);

        int cnt = 0;

		int flag = 0;

		int nownn;

		int nownt = nown;

		while(1){

            nownn = nownt % 10;

            nownt /= 10;

            cnt++;

            if(cnt > len)break;

			if(no[nownn] == 1){

				flag = 1;

				break;

			}

		}

		if(flag == 0){

			cout<<nown;

			break;

		}

		nown++;

	}

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

int n,k;

char a[15];

bool num[15];



bool check(int a) {

    int cnt=0;

    while (a) {

        if (!num[a%10]) return false;

        a/=10;

    }

    return true;

}



int main() {

    memset(num,1,sizeof(num));

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

    int tmp;

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

        scanf("%d",&tmp);

        num[tmp]=0;

    }

    int ans=n;

    while (!check(ans)) ans++;

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long llong;



int main(void) {

	int n, k; cin >> n >> k;

	vector<int> dislike(k);

	for (int i = 0; i < k; i++) cin >> dislike[i];



	for (int x = n; x < 100000; x++) {

		int tmp = x;

		set<int> s;

		while (tmp != 0) {

			s.insert(tmp % 10);

			tmp /= 10;

		}



		bool flag = true;



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

			if (s.count(dislike[i])) {

				flag = false;

				break;

			}

		}

		if (flag) {

			cout << x << endl;

			break;

		}

	}



	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long llong;



int main(void) {

	int n, k; cin >> n >> k;

	vector<int> dislike(10);

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

		int a; cin >> a;

		dislike[a]++; //嫌いな数字の添え字に1を立てる

	}



	int ans = n;

	while (true) {

		bool flag = true;

		int tmp = ans;

		while (tmp != 0) {

			// 嫌いな数字が含まれているかチェックする

			if (dislike[tmp % 10] == 1) {

				flag = false;

				break;

			}

			tmp /= 10;

		}



		if (flag) {

			cout << ans << endl;

			break;

		}

		ans++;

	}



	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;



int main(){

  int N,K; cin >> N >> K;

  

  vector<int> vec; 

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

    int d; cin >> d;  vec.push_back(d);}

  

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

    

    bool flag = true;

    

    int tmp = i;

    set<int> s;

    while( tmp > 0){

      s.insert( tmp% 10); tmp /= 10;}

    //　s中にあって、vecにもある数があればfalse

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

      if(s.count( vec[j])){ flag = false;} }

    

    if( flag){ cout << i << endl; break;}

  }

  

  return 0;}

    

    

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>



using namespace std;



bool num[10];

// true →　useable



int main(){

int N,K; 

 cin >> N >> K;

  

  for(int i = 0; i < 10; i++){ num[i] = true;}

  

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

    int d; cin >> d;

    num[d] = false;}

  

 

  int pay = N;

  

  while(1){

     int k = pay; bool flag = true;

    while( k > 0){

     if( !num[k % 10]){ flag = false;}

      k /= 10;}

    

    if( flag){ break; }

    pay++;

  }

  

  cout << pay << endl; return 0;}

    

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<string>

#include<map>

using namespace std;



int main(){

    int n, k;

    cin >> n >> k;

    map<string, bool> d;



    int x;

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

        cin >> x;

        d[to_string(x)] = true;

    }



    string s;

    bool check = true;

    string z;

    while (1){

        s = to_string(n);

        check = true;

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

            z = s[i];

            if (d[z]) check = false;

        }



        if (check) break;

        n++;

    }



    cout << n << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cmath>

#include<cstring>

#include<vector>

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

#define sc(x) scanf("%d",&x);

int main(){

    int n, k;

    sc(n) sc(k)

    int x, d[10];

    fill(d, d + 10, 0);

    REP(i, k){

        sc(x)

        d[x] = 1;

    }



    int check, ans = n;

    while(1){

        check = ans;

        while (check > 0){

            if (d[check % 10] == 1){

                ans++;

                break;

            }else check /= 10;

        }

        if (check == 0) break;

    }

    cout << ans << endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*------------------------------------

.....Bismillahir Rahmanir Rahim.......

created by muslim.time: 2:24:23 pm....

------------------------------------*/

#include <iostream>

#include <algorithm>

#include <stdio.h>

#include <cmath>

#include <vector>

#include <set>

#include <map>

#include <cstring>

#include <unordered_map>

#include <queue>

#define   mod  998244353

#define   int  long long 

#define   ld long double

#define   pb push_back

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

#define  ff first

#define  ss second

#define  pii  pair<int,int>

using namespace std;



inline void solve(){ 

    map <int,bool> mp; 

    int yen; cin>> yen;

    int n; cin>>n;

    while (n--){

        int a; cin>>a;

        mp[a]=true;

    }

    while (1){

        string s=to_string(yen);

        int l=s.size();

        bool ok=true;

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

            if (mp[s[i]-'0']) {

                ok=false;

                break;

            }

        }

        if (ok) break;

        yen++;

    }

    cout << yen << endl;

}



signed main()

{

    int n=1; // cin>>n;

    while (n--) solve();

    return 0;

}


// Optimized solution to the same problem (faster):
/*------------------------------------ 

........Bismillahir Rahmanir Rahim.... 

..........created by Abdul Aziz....... 

------------------------------------*/ 

#include <iostream> 

#include <algorithm> 

#include <stdio.h> 

#include <cmath> 

#include <vector> 

#include <set> 

#include <map> 

#include <cstring> 

#include <unordered_map> 

#include <queue> 

#define   mod  998244353 

#define   int  long long 

#define   ld   long double 

#define   pb   push_back 

#define   vi  vector<int> 

#define   dbg(x)  cerr << #x << " = " << x << '\n' 

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

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

#define   ff   first 

#define   ss   second 

#define   pii  pair<int,int> 

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

using namespace std; 

 

int n,k; 

map <int,bool> mp; 

int h[9],l=0,ans=100000000; 

 

void fun(int num){ 

	if (num >= n){

		ans = min(ans,num);

		return;

	}

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

		int x=num*10+h[i];

		if (x) fun(x);

	}

} 

 

inline void solve(){ 

    cin >> n >> k ; 

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

    	int a; cin >> a; 

    	mp[a] = true; 

    } 

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

    	if (!mp[i]) h[l++] = i; 

    fun(0);

    cout << ans << endl;

}



signed main()

{

    int n=1; // cin>>n;

    while (n--) solve();

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



#ifdef _DEBUG

#define debug(x) cout<<#x<<": "<<x<<endl

#else

#define debug(x)

#endif



using namespace std;



int main() {

    int N; int K;

    cin >> N >> K;

    set<int> ds;

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

        int d;

        cin >> d;

        ds.insert(d);

    }



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

        string n_str = to_string(n);

        bool found = false;

        for (const auto d : n_str) {

            if (ds.count(d - '0')) {

                found = true;

            }

        }

        if (found) { continue; }

        cout << n << endl;

        break;

    }

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



#ifdef _DEBUG

#define debug(x) cout<<#x<<": "<<x<<endl

#else

#define debug(x)

#endif



using namespace std;



int main() {

    string N; int K;

    cin >> N >> K;

    set<int> ds;

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

        int d;

        cin >> d;

        ds.insert(d);

    }



    int min_not_in_ds = -1;

    for (int t = 0; t <= 9; ++t) {

        if (!ds.count(t)) {

            min_not_in_ds = t;

            break;

        }

    }

    assert(min_not_in_ds >= 0);



    bool can_pay = true;

    deque<int> res;

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

        int di = N[N.size() - 1 - i] - '0';

        if (can_pay) {

            for (int t = di; t <= 9; ++t) {

                if (!ds.count(t)) {

                    res.push_front(t);

                    if (t > di) {

                        for (int k = 1; k < res.size(); ++k) {

                            res[k] = min_not_in_ds;

                        }

                    }

                    goto next1;

                }

            }

            can_pay = false;

            res.push_front(min_not_in_ds);

next1:;

        } else {

            for (int t = di + 1; t <= 9; ++t) {

                if (!ds.count(t)) {

                    res.push_front(t);

                    for (int k = 1; k < res.size(); ++k) {

                        res[k] = min_not_in_ds;

                    }

                    can_pay = true;

                    goto next2;

                }

            }

            res.push_front(min_not_in_ds);

next2:;

        }

    }



    if (!can_pay) {

        for (int t = 1; t <= 9; ++t) {

            if (!ds.count(t)) {

                res.push_front(t);

                break;

            }

        }

    }

    for (auto d : res) {

        cout << d;

    }

    cout << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#define __USE_MINGW_ANSI_STDIO 0

#include <bits/stdc++.h>

using namespace std;

#define ll long long int

#define rep(i,n) for( int i = 0; i < n; i++ )

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF 2000000000

#define mod 1000000007

#define INF2 1000000000000000000





int main(void)

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int N, K;

    cin >> N >> K;

    int D[K];

    rep(i, K) {

        cin >> D[i];

    }

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

        int flag = 0;

        string tmp = std::to_string(i);

        rep(k, tmp.length()) {

            rep(j, K) {

                //cout << tmp[k] - '0' << " " << D[j] << endl;

                if (tmp[k] - '0' == D[j]) {

                    flag = 1;

                    break;

                }

            }

            if (flag == 1) break;

        }

        if (flag == 0) {

            cout << i << endl;

            return 0;

        }

    }





    return 0;

}


// Optimized solution to the same problem (faster):
#include "bits/stdc++.h"

using namespace std;

#define ll long long int

#define rep(i,n) for( int i = 0; i < n; i++ )

#define rrep(i,n) for( int i = n; i >= 0; i-- )

#define REP(i,s,t) for( int i = s; i <= t; i++ )

#define RREP(i,s,t) for( int i = s; i >= t; i-- )

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF 2000000000

#define mod 1000000007

#define INF2 1000000000000000000



int D[9];

int K;

bool check(int num) {

    while(num > 0){

        int tmp = num % 10;

        rep(i, K) {

            if (tmp == D[i]) return false;

        }

        num /= 10;

    }

    return true;

}





int main(void)

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int N;

    cin >> N >> K;



    rep(i, K) cin >> D[i];

    while(true) {

        if (check(N)) {

            cout << N << endl;

            return 0;

        }

        N++;

    }







    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <stdio.h>

#include <algorithm>

#include <functional>

#include <iostream>

#include <string>

#include <vector>

using namespace std;



//前提:解は必ず存在する

int main() {

  int N, K;

  cin >> N >> K;



  vector<int> D;



  //配列D、嫌いな数字を入れていく。

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

    int d;

    cin >> d;

    D.push_back(d);

  }



  // 嫌いな数字が出現した際に立つフラグ

  bool flag;



  for (int ans = N; ans <= 99999; ans++) {

    // ansを文字列に変換

    string str = to_string(ans);

    flag = false;



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

      // 嫌いな数字を文字に変換

      char judge = '0' + D[i];



      // ans中にD[i]が出現したらフラグを立てる

      if (str.find(judge) != string::npos) {

        flag = true;

        break;

      }

    }



    // 嫌いな数字が出現してなかったら表記して終了

    if (flag == false) {

      cout << ans << endl;

      return 0;

    }

  }

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <functional>

#include <cmath>

#include <iomanip>

#include <stack>

#include <queue>

#include <numeric>

#include <map>

#include <unordered_map>

#include <set>

#include <fstream>

#include <chrono>

#include <random>

#include <bitset>

#define rep(i,n) for(int i=0;i<(n);i++)

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

#define rall(x) x.rbegin(), x.rend()

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

#define pb push_back

using ll = long long;

using namespace std;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}

ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}





bool ok(int N,vector<int>& D){

  while(N){

    rep(i,sz(D)){

      if(N%10==D[i]) return false;

    }

    N/=10;

  }

  return true;

}



void solve(){

  int N, K; cin >> N >> K;

  vector<int> D(K); rep(i,K) cin >> D[i];

  while(1){

    if(ok(N,D)) {

      cout << N << endl;

      break;

    }

    else N++;

  }

}



int main(){

  solve();

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main() {

  int n, k;

  bool flag = true;

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

  int d[k];

  for(int i = 0; i < n; i++) scanf("%d", &d[i]);

  while(flag) {

    flag = false;

    string str = to_string(n);

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

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

        string tmp = to_string(d[i]);

        if(str.at(j) == tmp.at(0)) {

          flag = true;

          break;

        }

      }

      if(flag) break;

    }

    if(flag) n++;

  }

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

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

int main() {

  int n, k;

  bool flag = true;

  cin >> n >> k;

  vector<int> d(k);

  for(int i = 0; i < k; i++) cin >> d.at(i);

  while(flag) {

    flag = false;

    int tmp = n;

    while(tmp) {

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

        if ((tmp%10) == d.at(i)) {

          tmp = 0;

          flag = true;

          break;

        }

      }

      tmp /= 10;

    }

    if (flag) n++;

  }

  cout << n << endl;

  return 0;

}

// Fastest known solution for this problem: