stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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++;

	}

	

	

 } 

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

        }

		

	}

}

// Optimized solution to the same problem (faster):
#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;

		}

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

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


#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define rep(i, n) for (int i = 0; i < (n); i++)

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using P = pair<int, int>;

const int MOD = 1000000007;

// MAX int 2,147,483,647

// MAX O(n) 10^18



int main() {

    int N, K;

    cin >> N >> K;

    vector<int> D(K);

    rep(i, K) cin >> D.at(i);



    string ans;

    for (int i = N; i < 1000000; i++) { // 100000 * 5 * 10 -> OK

        string digits = to_string(i);

        bool isOk = true;

        for (char digit : digits) {

            rep(j,K) {

                if (digit - '0' == D.at(j)) isOk = false;

            }

        }

        if (isOk) {

            ans = digits;

            break;

        }

    }



    cout << ans << endl;



    return 0;

}


// Optimized solution to the same problem (faster):
#define rep(i, n) for (int i = 0; i < (n); i++)

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using P = pair<int, int>;

const int MOD = 1000000007;

// MAX int 2,147,483,647

// MAX O(n) 10^



vector<int> D;



bool isValid(int x) {

    while(x > 0) {

        if (find(D.begin(), D.end(), x % 10) != D.end()) return false;

        x /= 10;

    }

    return true;

}



int main() {

    int N, K;

    cin >> N >> K;

    int tmp;

    rep(i, K) {

        cin >> tmp;

        D.push_back(tmp);

    }



    int ans;

    for (int i = N; i < 1000000; i++) { // 100000 * 5 * 10 -> OK

        if (isValid(i)) {

            ans = i;

            break;

        }

    }



    cout << ans << endl;



    return 0;

}


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

#include <vector>

#include <cstdlib>

using namespace std;

int main(){

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

    cin>>n>>k;

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

        cin>>l;

        d[l]=1;

    }

    string retstr;

    bool flag=true;

    int x;

    while(flag){

        flag=false;

        retstr=to_string(n);

        x=n;

        while(x>0){

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

                n++;

                flag=true;

                break;

            }

            x/=10;

        }

    }

    cout<<n;

}

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

#include <vector>

using namespace std;

int main(){

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

    cin>>n>>k;

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

        cin>>l;

        d[l]=1;

    }

    bool flag=true;

    int x;

    while(flag){

        flag=false;

        x=n;

        while(x>0){

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

                n++;

                flag=true;

                break;

            }

            x/=10;

        }

    }

    cout<<n;

}

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

#include <ios>

#include <iomanip>

#include <algorithm>

#include <string>

#include <vector>

#include <map>

#include <set>

#include <cstdlib>

#include <cstring>

#include <cmath>

using namespace std;



#define MOD 1e9+7

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

typedef long long ll;



#define MAX_N 100000

#define MAX_V 100

#define MAX_E 100



//--------------------------



//void dfs(string, int);



int N, K;

int d[10];

bool flag = true;



int main() {



  cin >> N >> K;

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



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

    flag = true;

    string s = to_string(i);

    rep(j, K) {

      if(s.find(to_string(d[j]))!=string::npos) {

        flag = false;

      }

    }



    if(flag) {

      cout << s << endl;

      break;

    }

  }



  return 0;

}


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

#include <ios>

#include <iomanip>

#include <algorithm>

#include <string>

#include <vector>

#include <map>

#include <set>

#include <cstdlib>

#include <cstring>

#include <cmath>

using namespace std;



#define MOD 1e9+7

#define INF 1e9+7

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

typedef long long ll;



#define MAX_N 100000

#define MAX_V 100

#define MAX_E 100



//--------------------------



int dfs(int n);



int N, K, D;

int d[10];



int main() {



  cin >> N >> K;

  rep(i, K) {

    cin >> D;

    d[D] = 1;

  }



  cout << dfs(0) << endl;



  return 0;

}



int dfs(int n) {



  int min_money = INF;



  if(n>=N) {

    return n;

  }



  rep(i, 10) {

    if(n==0&&i==0) continue;

    if(d[i]==0) {

      min_money = min(min_money, dfs(n*10+i));

    }

  }



  return min_money;

}


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

#include <set>

#include <string>



using namespace std;



int main() {

		int N, K;

		cin >> N >> K;

		set<int> st;

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

				int t;

				cin >> t;

				st.insert(t);

		}



		bool flg = true;

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

				string S = to_string(i);

				if (i >= N) {

						int t = i;

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

								if (st.find(t%10) != st.end()) {

										flg = false;

										break;

								} else {

										t /= 10;

								}

						}



						if (!flg) {

								flg = true;

						} else {

								cout << i << endl;

								return 0;

						}

				}

		}

		return 0;

}


// Optimized solution to the same problem (faster):
#define _GLIBCXX_DEBUG

#include <iostream>

#include <cstdio>

#include <vector>

#include <algorithm>

#include <utility>

#include <string>

using namespace std;

typedef long long ll;

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



int main() {

		int N, K;

		cin >> N >> K;

		vector<bool> D(10, false);

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

				int t;

				cin >> t;

				D[t] = true;

		}



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

				bool flg = true;

				string S = to_string(i);

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

						if (D[S[j]-'0'] == true) {

								flg = false;

								break;

						}

				}



				if (flg) {

						cout << i << endl;

						return 0;

				}

		}

		return 0;

}


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

#include <vector>

#include <cmath>

using namespace std;



int main(void) {

	int prc, num, i = 0, j, buf, ans = 0, len;

	bool bad;

	cin >> prc >> num;

	vector<bool> d(10, true);

	for (; i < num; i++) {

		cin >> buf;

		d[buf] = false;

	}

	ans = prc-1;

	do {

		ans++;

		buf = ans;

		len = 0;

		while (buf > 0) {

			buf /= 10;

			len++;

		}

		vector<int> k(len);

		bad = false;

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

			k[j] = (ans / int(pow(10, len - 1 - j))) % 10;

			if (!d[k[j]])

				bad = true;

		}

	} while (bad);

	cout << ans << "\n";

	return 0;

}

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

#include <vector>



using namespace std;



int Judge(int n, vector<int> &d) {

	do {

		if (d[n % 10])

			return false;

		n /= 10;

	}while (n > 0);

	return true;

}



int main(void) {

	int ans, k, i, a;

	vector<int> d(10, false);

	cin >> ans >> k;

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

		scanf("%d", &a);

		d[a] = true;

	}

	while (!Judge(ans, d)) {

		ans++;

	}

	cout << ans << "\n";

	return 0;

}

// Fastest known solution for this problem: