stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>

#include <set>



using namespace std;



typedef long long i64;



set<int> D;

bool hate(i64);



int main(void) {

    i64 N, K;

    cin >> N >> K;



    int d, i;

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

        cin >> d;

        D.insert(d);

    }



    while (hate(N)) {

        N++;

    }



    cout << N << endl;



    return 0;

}





bool hate(i64 N) {

    int d;

    while (N) {

        d = N % 10;

        if (D.count(d)) return true;



        N /= 10;

    }

    return false;

}


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



using namespace std;



bool is_valid(const int D[10], int N) {

    while (N) {

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



        N /= 10;

    }

    return true;

}



int main() {

    int N, K;

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



    int D[10]={};

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

        int d;

        scanf("%d", &d);

        ++D[d];

    }



    while (!is_valid(D, N))

        ++N;



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

    return 0;

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

#include <set>



using namespace std;



bool is_valid(const set<int> &D, int N) {

    while (N) {

        if (D.count(N%10)) return false;



        N /= 10;

    }

    return true;

}



int main() {

    int N, K;

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



    set<int> D;

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

        int d;

        scanf("%d", &d);

        D.insert(d);

    }



    while (!is_valid(D, N))

        ++N;



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

    return 0;

}


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



using namespace std;



bool is_valid(const int D[10], int N) {

    while (N) {

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



        N /= 10;

    }

    return true;

}



int main() {

    int N, K;

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



    int D[10]={};

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

        int d;

        scanf("%d", &d);

        ++D[d];

    }



    while (!is_valid(D, N))

        ++N;



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

    return 0;

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

#include<algorithm>

using namespace std;

int N,k,a[20];

bool book[20];

bool Check(int i) {

	char s[20]={};

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

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

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

			return false;

	return true;

}

int main() {

	#ifdef LOACL

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

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

	#endif

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

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

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

		book[a[i]]=true;

	}

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

		if(Check(i)) {

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

			break;

		}

	return 0;

}

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



using namespace std;



int n, k, arr[100];



void solve() {

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

		int tmp = x;

		int flag = 1;

		while(tmp) {

			int num = tmp % 10;

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

				if(num == arr[i]){

					flag = 0;

					break;

				}

			}

			tmp = tmp / 10;

			if(!flag) break;

		}

		if(flag){

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

			return ;

		}

	}

}



int main() {

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

		for(int i = 1; i <= k; ++i) scanf("%d", arr + i);

		solve(); 

	} 

	return 0;

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

#include<map>  

#include<stack>  

#include<cmath>  

#include<cstdio>  

#include<queue>  

#include<vector>  

#include<cstring> 

#include<climits>  

#include<iostream> 

#include<algorithm> 

using namespace std; 

int read(){ 

    int f=1,x=0; 

    char c=getchar(); 

    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 

    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} 

    return f*x; 

}

#define MAXN 300

#define INF 0x3f3f3f3f

int pan[100];

bool check(int x){

	if(pan[x%10]) return 0;

	while(x){

		if(pan[x%10]) return 0;

		x/=10;

	}

	return 1;

}

int main(){

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

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

		pan[read()]=1;

	while(1){

		if(check(n)){

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

			return 0;

		}

		n++;

	}

    return 0;

}

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



using namespace std;



int n, k, arr[100];



void solve() {

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

		int tmp = x;

		int flag = 1;

		while(tmp) {

			int num = tmp % 10;

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

				if(num == arr[i]){

					flag = 0;

					break;

				}

			}

			tmp = tmp / 10;

			if(!flag) break;

		}

		if(flag){

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

			return ;

		}

	}

}



int main() {

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

		for(int i = 1; i <= k; ++i) scanf("%d", arr + i);

		solve(); 

	} 

	return 0;

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

#include <cstring>

#include <string>

using namespace std;



int main(){

	int n,k;

	int x,m;

	int a[11];

	int ans[10];

	

	memset(a,1,sizeof(a));

	cin >> n >> k;

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

		cin >> x;

		a[x] = 0;

	}

	

	while(1){

	

		int i = 0;

		m = n;

		while(n){

			ans[i++] = n%10;

			n/=10;

		}

		int flag = 0;

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

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

				if(!a[j]&&ans[k]==j){

					m++;

					n = m;

					flag = 1;

					break;

				}

			}

			if(flag){

				break;

			}

		}

		

		if(!n){

			break;

		}

	}

	cout << m;	

}

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



using namespace std;



int n, k, arr[100];



void solve() {

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

		int tmp = x;

		int flag = 1;

		while(tmp) {

			int num = tmp % 10;

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

				if(num == arr[i]){

					flag = 0;

					break;

				}

			}

			tmp = tmp / 10;

			if(!flag) break;

		}

		if(flag){

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

			return ;

		}

	}

}



int main() {

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

		for(int i = 1; i <= k; ++i) scanf("%d", arr + i);

		solve(); 

	} 

	return 0;

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

using namespace std;

int s[11];

 int ss[11];

int main()

{

int n,m;

 int sum;sum=0;cin>>n>>m;

 int x;

 int a;

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

 {

     cin>>a;

     s[a]=1;

 }

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

    if(i>=n)

 {

     int a;a=i;

     int k;k=0;

     while(a)

     {

         if(s[a%10])k=1;

         a=a/10;

     }

     if(k==0){cout<<i;break;}



 }

}


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



using namespace std;



int n, k, arr[100];



void solve() {

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

		int tmp = x;

		int flag = 1;

		while(tmp) {

			int num = tmp % 10;

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

				if(num == arr[i]){

					flag = 0;

					break;

				}

			}

			tmp = tmp / 10;

			if(!flag) break;

		}

		if(flag){

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

			return ;

		}

	}

}



int main() {

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

		for(int i = 1; i <= k; ++i) scanf("%d", arr + i);

		solve(); 

	} 

	return 0;

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

#include <algorithm>

#include <cstdio>

#include <cstring>

using namespace std;

typedef long long ll;

int ans,v, n;

int tt[500];

int vis[200];

void dfs(int s) {

    if(s >= n) {

        ans = min(ans, s);

        return;

    }

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

        if(!vis[i]) {

            dfs(s * 10 + i);

        }

    }

}

int main() {

    string s;

    int k, a;

    while(cin >> n >> k) {

        memset(vis, 0, sizeof vis);

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

            scanf("%d", &a), vis[a] = 1;

        ans = 1e9;

        for(int i = 9; i >= 0; i--) {

            if(!vis[i] && i) dfs(i);

        }

        cout << ans << endl;

    }

    return 0;

}


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



using namespace std;



int n, k, arr[100];



void solve() {

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

		int tmp = x;

		int flag = 1;

		while(tmp) {

			int num = tmp % 10;

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

				if(num == arr[i]){

					flag = 0;

					break;

				}

			}

			tmp = tmp / 10;

			if(!flag) break;

		}

		if(flag){

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

			return ;

		}

	}

}



int main() {

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

		for(int i = 1; i <= k; ++i) scanf("%d", arr + i);

		solve(); 

	} 

	return 0;

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

#include<cmath>

#include<cstring>

#include<cstdio>

#include<algorithm>

using namespace std;

int n,k,vis[10];

int check(int n){

	while(n){

		if(vis[n%10]==1)

		return 0;

		n/=10;

	}

    return 1;

	}

int main()

{

	cin>>n>>k;

	memset(vis,0,sizeof(vis));

	int a;

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

	cin>>a;

	vis[a]=1;

}

	int i=n;

	while(1){

		if(check(i)){

			cout<<i<<endl;

			break;

		}

		i++;

	}

	

	

 } 

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



using namespace std;



int n, k, arr[100];



void solve() {

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

		int tmp = x;

		int flag = 1;

		while(tmp) {

			int num = tmp % 10;

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

				if(num == arr[i]){

					flag = 0;

					break;

				}

			}

			tmp = tmp / 10;

			if(!flag) break;

		}

		if(flag){

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

			return ;

		}

	}

}



int main() {

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

		for(int i = 1; i <= k; ++i) scanf("%d", arr + i);

		solve(); 

	} 

	return 0;

}
// Slower C++ solution:
//#pragma GCC diagnostic error "-std=c++11"

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 5e5 + 5;

const ll inf = 0x3f3f3f3f3f;

bool dislike[100];

ll n,k;



bool judge(int n)

{

	while(n)

	{

		if(dislike[n%10]) return false;

		n/=10;

	}

	return true;

}



int main(){

	cin>>n>>k;

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

	{

		ll q;

		cin>>q;

		dislike[q]=1;

	}

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

	{

		if(judge(i))

		{

			cout<<i;

			return 0;

		}

	}

	return 0;

}

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



using namespace std;



int n, k, arr[100];



void solve() {

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

		int tmp = x;

		int flag = 1;

		while(tmp) {

			int num = tmp % 10;

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

				if(num == arr[i]){

					flag = 0;

					break;

				}

			}

			tmp = tmp / 10;

			if(!flag) break;

		}

		if(flag){

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

			return ;

		}

	}

}



int main() {

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

		for(int i = 1; i <= k; ++i) scanf("%d", arr + i);

		solve(); 

	} 

	return 0;

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

#include <cstdio>

#include <algorithm>

#include <cstring>

using namespace std;

int n,k,a[10];

int judge(int x)

{

    int p;

    while(x)

    {

        p = x % 10;

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

        {

            if(p == a[i])

                return false;

        }

        x /= 10;

    }

    return true;

}

int main()

{

    cin>>n>>k;

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

        cin>>a[i];

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

    {

        if(judge(i))

        {

            cout<<i<<endl;

            break;

        }

    }

    return 0;

}


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



using namespace std;



int n, k, arr[100];



void solve() {

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

		int tmp = x;

		int flag = 1;

		while(tmp) {

			int num = tmp % 10;

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

				if(num == arr[i]){

					flag = 0;

					break;

				}

			}

			tmp = tmp / 10;

			if(!flag) break;

		}

		if(flag){

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

			return ;

		}

	}

}



int main() {

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

		for(int i = 1; i <= k; ++i) scanf("%d", arr + i);

		solve(); 

	} 

	return 0;

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

#include<cstring>

#include<iostream>

#include<algorithm>

#include<cmath>

using namespace std;

int vis[11];

int check(int n)

{

	while(n)

	{

		if(vis[n%10]==1)

			return 0;

		n/=10;

	}

	return 1;

}

int main()

{

	int n,k;

	int x;

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



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

	    {

		   cin>>x;

		   vis[x]=1;

	    }

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

	    {

		   if(check(i))

		   {

                       cout<<i<<endl;

                        return 0;



                   }

	    }





	return 0;

}




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



using namespace std;



int n, k, arr[100];



void solve() {

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

		int tmp = x;

		int flag = 1;

		while(tmp) {

			int num = tmp % 10;

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

				if(num == arr[i]){

					flag = 0;

					break;

				}

			}

			tmp = tmp / 10;

			if(!flag) break;

		}

		if(flag){

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

			return ;

		}

	}

}



int main() {

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

		for(int i = 1; i <= k; ++i) scanf("%d", arr + i);

		solve(); 

	} 

	return 0;

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

#include <cmath>

#include <vector>

#include <map>

#include <iomanip>

#include <algorithm>

#include <sstream>

#include <string>

#include <math.h>

#include <set>

using namespace std;

 

int main() {

	ios::sync_with_stdio(false);

	int k,n,d,a[10]={};

	cin >> n >> k;

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

		cin >> d;

		a[d]=1;

	}

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

        string b = to_string(i);

		int count=0;

        for (int j=0;j<b.length();j++) if (a[b[j]-'0']!=1) count++;

      	if (count==b.length()) {

          		cout << i;

          		break;

        }

		

	}

}

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

#include <cmath>

#include <vector>

#include <map>

#include <iomanip>

#include <algorithm>

#include <sstream>

#include <string>

#include <math.h>

#include <set>

using namespace std;

 

int main() {

	ios::sync_with_stdio(false);

	int n, k, d[10] = {};

	cin >> n >> k;

	int a;

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

		cin >> a;

		d[a] = 1;

	}

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

		bool y=0;

		a=i;

      	while (a) {

          if (d[a%10]) y=1;

          a/=10;

        }

		if (!y) {

			cout << i;

			break;

		}

	}

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

#include <regex>

#define _USE_MATH_DEFINES

#include <math.h>



using namespace std;



#ifndef _DEBUG

#define main_ main

#endif

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)

#define INF (INT_MAX/2)

#define EPS (1.0e-8)

#define LINF (LONG_MAX/2)



typedef long long ll;

typedef unsigned long long ull;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef pair<int, int> pii;

typedef vector<bool> vb;



template <typename T>

using keyVal = pair<string, T>;

template<typename T>

bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {

	return left.second > right.second;

}



void init_global() {}



int main_() {

	cin.tie(0);

	ios::sync_with_stdio(false);



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

	vi D(K); FOR(i, 0, K) cin >> D[i];

	int ans;

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

		bool ok = true;

		for (int d : D) {

			string ns = to_string(n);

			string ds = to_string(d);

			int pos = ns.find(ds);

			if (pos != string::npos) {

				ok = false;

				break;

			}

		}



		if (ok) {

			ans = n;

			break;

		}

	}



	cout << ans << endl;

	return 0;

}


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

#include <regex>

#define _USE_MATH_DEFINES

#include <math.h>



using namespace std;



#ifndef _DEBUG

#define main_ main

#endif

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)

#define INF (INT_MAX/2)

#define EPS (1.0e-8)

#define LINF (LONG_MAX/2)



typedef long long ll;

typedef unsigned long long ull;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef pair<int, int> pii;

typedef vector<bool> vb;



template <typename T>

using keyVal = pair<string, T>;

template<typename T>

bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {

	return left.second > right.second;

}



void init_global() {}



int main_() {

	cin.tie(0);

	ios::sync_with_stdio(false);



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

	vi D(K); FOR(i, 0, K) cin >> D[i];

	int ans;

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

		bool ok = true;

		for (int d : D) {

			int t = n;



			while (t > 0) {

				if (t % 10 == d) {

					ok = false;

					break;

				}

				t /= 10;

			}

			if (!ok) break;

		}



		if (ok) {

			ans = n;

			break;

		}

	}



	cout << ans << endl;

	return 0;

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

#include <string>

#include <vector>

#include <algorithm>



using namespace std;



int main() {

	int N, K;

	cin >> N >> K;

	vector<int> D(K);



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

		cin >> D.at(i);

	}



	int ans = N;

	bool cdt = false;



	while (!cdt) {

		cdt = true;

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

			int a = ans;

			while (a > 0) {

				if (a % 10 == D.at(i)) cdt = false;

				a /= 10;

			}

		}

		ans++;

	}



	cout << ans - 1 << endl;



	return 0;

}

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

#include <string>

#include <vector>

#include <algorithm>



using namespace std;



int main() {

	int N, K;

	cin >> N >> K;

	vector<int> D(K);



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

		cin >> D.at(i);

	}



	int ans = N;

	bool cdt = false;



	while (!cdt) {

		cdt = true;

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

			int a = ans;

			while (a > 0) {

				if (a % 10 == D.at(i)) {

					cdt = false;

					ans++;

					break;

				}

				a /= 10;

			}

		}

	}



	cout << ans << endl;



	return 0;

}
// Slower C++ solution:


#include "bits/stdc++.h"



template<typename T>

T get_value(std::istream& is);



int getMinNum(int _nOriginal, const std::set<char>& _avoid)

{

	std::string org = std::to_string(_nOriginal);

	for (auto& c : org)

	{

		if (_avoid.find(c) != _avoid.end())

		{

			return getMinNum(_nOriginal + 1, _avoid);

		}

	}



	return _nOriginal;

}





int getMinNum_bsearch(int _nOriginal, const std::vector<char>& _avoid)

{

	std::string org = std::to_string(_nOriginal);

	for (auto& c : org)

	{

		if (std::binary_search(_avoid.cbegin(), _avoid.cend(), c))

		{

			return getMinNum_bsearch(_nOriginal + 1, _avoid);

		}

	}



	return _nOriginal;

}



int main()

{

	std::cin.sync_with_stdio(false);

	std::cin.tie(nullptr);



	int N, K;



	std::cin >> N >> K;

	std::vector<char> v(K);

	//std::set<char> s;



	for (auto& e : v) {

		std::cin >> e;

		//s.insert(e);

	}



	//int answer = getMinNum(N, s);

	int answer = getMinNum_bsearch(N, v);



	std::cout << answer << std::endl;



	return 0;

};





template<typename T>

inline T get_value(std::istream& is)

{

	T v;

	is >> v;

	return v;

}


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

 

template<typename T>

T get_value(std::istream& is);

 

 

int getMinNum_div(int _nOriginal, const std::vector<int>& _avoid)

{

	for (int i = _nOriginal; i < 100000; i++)

	{

		bool bFound = false;

		int c, d;

 

		c = i;

		while (c > 0 && !bFound)

		{

			div_t dv = div(c, 10);

			if (std::binary_search(_avoid.cbegin(), _avoid.cend(), dv.rem))

			{

				bFound = true;

				break;

			}

 

			c = dv.quot;

		}

		

		if (!bFound) return i;

	}

 

	return -1;

}

 

 

 

 

int main()

{

	std::cin.sync_with_stdio(false);

	std::cin.tie(nullptr);

 

	int N, K;

 

	std::cin >> N >> K;

	std::vector<int> v(K);

 

	for (auto& e : v) {

		std::cin >> e;

	}

 

	int answer = getMinNum_div(N, v);

	std::cout << answer << std::endl;

 

	return 0;

};

 

 

template<typename T>

inline T get_value(std::istream& is)

{

	T v;

	is >> v;

	return v;

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



template<typename T>

T get_value(std::istream& is);



int getMinNum_recursive(int _nOriginal, const std::set<char>& _avoid)

{

	std::string org = std::to_string(_nOriginal);

	for (auto& c : org)

	{

		if (_avoid.find(c) != _avoid.end())

		{

			return getMinNum_recursive(_nOriginal + 1, _avoid);

		}

	}



	return _nOriginal;

}





int getMinNum_bsearch_recursive(int _nOriginal, const std::vector<char>& _avoid)

{

	std::string org = std::to_string(_nOriginal);

	for (auto& c : org)

	{

		if (std::binary_search(_avoid.cbegin(), _avoid.cend(), c))

		{

			return getMinNum_bsearch_recursive(_nOriginal + 1, _avoid);

		}

	}



	return _nOriginal;

}



int getMinNum_bsearch(int _nOriginal, const std::vector<char>& _avoid)

{

	for (int i = _nOriginal; i < 100000; i++)

	{

		std::string strNum = std::to_string(i);

		bool bFound = false;

		for (auto& c : strNum)

		{

			if (std::binary_search(_avoid.cbegin(), _avoid.cend(), c))

			{

				bFound = true;

				break;

			}

		}



		if (!bFound) return i;

	}



	return -1;

}







int main()

{

	std::cin.sync_with_stdio(false);

	std::cin.tie(nullptr);



	int N, K;



	std::cin >> N >> K;

	std::vector<char> v(K);

	//std::set<char> s;



	for (auto& e : v) {

		std::cin >> e;

		//s.insert(e);

	}



	//int answer = getMinNum(N, s);

	//int answer = getMinNum_bsearch(N, v);

	int answer = getMinNum_bsearch(N, v);

	std::cout << answer << std::endl;



	return 0;

};





template<typename T>

inline T get_value(std::istream& is)

{

	T v;

	is >> v;

	return v;

}


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

 

template<typename T>

T get_value(std::istream& is);

 

 

int getMinNum_div(int _nOriginal, const std::vector<int>& _avoid)

{

	for (int i = _nOriginal; i < 100000; i++)

	{

		bool bFound = false;

		int c, d;

 

		c = i;

		while (c > 0 && !bFound)

		{

			div_t dv = div(c, 10);

			if (std::binary_search(_avoid.cbegin(), _avoid.cend(), dv.rem))

			{

				bFound = true;

				break;

			}

 

			c = dv.quot;

		}

		

		if (!bFound) return i;

	}

 

	return -1;

}

 

 

 

 

int main()

{

	std::cin.sync_with_stdio(false);

	std::cin.tie(nullptr);

 

	int N, K;

 

	std::cin >> N >> K;

	std::vector<int> v(K);

 

	for (auto& e : v) {

		std::cin >> e;

	}

 

	int answer = getMinNum_div(N, v);

	std::cout << answer << std::endl;

 

	return 0;

};

 

 

template<typename T>

inline T get_value(std::istream& is)

{

	T v;

	is >> v;

	return v;

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

using namespace std;

int main(){

  cin.tie(0);

  ios::sync_with_stdio(false);

  int n, k;

  cin >> n >> k;

  vector<bool> chk(10, true);

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

    int d;

    cin >> d;

    chk[d] = false;

  }

  string m = to_string(n);

  while(1){

    bool flag = true;

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

      if(!chk[m[i]-'0']) flag = false;

    }

    if(flag) break;

    n++;

    m = to_string(n);

  }

  cout << n << endl;

}

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

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

using namespace std;

using ll = long long;

using P = pair<int, int>;

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

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



int main(){

	cin.tie(0);

	ios::sync_with_stdio(false);

    int n, k;

    cin >> n >> k;

    vector<bool> dislike(10, false);

    rep(i,k){

        int d;

        cin >> d;

        dislike[d] = true;

    }

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

        int num = i;

        bool ok = true;

        while(num > 0){

            if(dislike[num%10]){

                ok = false;

                break;

            }

            num /= 10;

        }

        if(ok){

            cout << i << endl;

            return 0;

        }

    }

	return 0;

}