stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.2186259940706219x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.1742879860647228x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 2.493103422289049x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.1250723212954066x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.1944771316155813x):
#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;

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

using namespace std;

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

#define  all(x) (x).begin(),(x).end()     // 昇順ソート

#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート

#define  INF 1LL << 60

typedef long long int LL;

typedef long long int ll;

#define pll pair<ll, ll>

#define F first

#define S second

const int MOD = 1000000007;

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

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

//sort(all(x))とするとソートできるよ

// 10^x は pow(10,(x)) 

// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

unsigned GetDigit(unsigned num){

    if(num == 0)return 1;

    return log10(num)+1;

}



int main(){

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

    vector<int> D(K);

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

    int ans = N;

    bool ok = true;

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

        int keta = GetDigit(i);

        ok = true;

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

            int tmp = 0;

            tmp = i % (int)pow(10,j);

            tmp = tmp / (int)pow(10,j-1);      //  tmpにj桁目の数字を格納  

            rep(k,K){

                if(tmp == D[k])ok = false;

            }

        }

        if(ok){

            ans = i;

            break;

        }

    }

    cout << ans << endl;

}




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

using namespace std;

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

#define all(x)(x).begin(), (x).end() // 昇順ソート

#define rall(v)(v).rbegin(), (v).rend() // 降順ソート

#define INF 1LL << 60

typedef long long int LL;

typedef long long int ll;

#define pll pair < ll, ll >

#define F first

#define S second

const int MOD = 1000000007;

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

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

// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)



int main() {

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

    vector<bool> ok(10);

    rep(i,K){

        int t;cin >> t;

        ok[t] = true;

    }   



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

        string tmp = std::to_string(i);

        bool ch = true;

        rep(i,tmp.size()){

            int t = tmp[i] - '0';

            if(ok[t])ch = false;

        }

        if(ch){

            cout << i << endl;

            break;

        }

    }

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

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

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

#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)

#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)

#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)

#define ALL(n) begin(n), end(n)

using ll = long long;

using namespace std;



int main(){

	int n, k;

	cin >> n >> k;

	set<int> d;

	rep(i, k){

		int in;

		cin >> in;

		d.insert(in);

	}

	int ans = n;

	while(1){

		string sn = to_string(ans);

		// cerr << ans << endl;

		bool flag = true;

		rep(i, sn.size()){

			if(d.count(sn[i] - '0') == 1) flag = false;

		}

		if(flag == true){

			cout << ans << endl;

			return 0;

		}

		ans++;

	}

	return 1;

}

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

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

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

#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)

#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)

#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)

#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)

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

using ll = long long;

using namespace std;



bool chk(int n, vector<bool> &use){

  if(n == 0){

    return !use.at(0);

  }

  while(n != 0){

    if(use.at(n%10) == true) return false;

    n /= 10;

  }

  return true;

}



int main(){

  int n, k;

  cin >> n >> k;

  vector<bool> use(10, false);

  rep(i, k){

    int in;

    cin >> in;

    use.at(in) = true;

  }

  while(1){

    if(chk(n, use) == true){

      cout << n << endl;

      return 0;

    }

    n++;

  }

  return 0;

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

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

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



using namespace std;



typedef long long ll;

typedef pair<int, int> P;



bool digit[10];	// 禁止する数字



string i2s(int n){

	stringstream ss;

	int res;

	ss << n;



	return ss.str();

}



bool is_ok(int curr){

	string s = i2s(curr);

	rep (i, s.length()){

		if (!digit[(int)(s[i] - '0')]) return false;

	} // end rep

	return true;

}



int main()

{

	fill(digit, digit + 10, true);

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	int N; cin >> N;

	int K; cin >> K;

	rep (i, K){

		int D; cin >> D;

		digit[D] = false;

	} // end rep

 

	int res = 0;

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

		bool ok = true;

		if (is_ok(i)){

			res = i; break;

		} // end if

	} // end for



	cout << res << endl;



	return 0;

}

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

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

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



using namespace std;



typedef long long ll;

typedef pair<int, int> P;



bool is_ok(int cand, set<int> d){

	while(cand > 0){

		int curr = cand % 10;

		if (d.count(curr)){

			return false;

		} // end if

		cand /= 10;

	} // end while



	return true;

}



int main()

{

	ios_base::sync_with_stdio(0);

	cin.tie(0);

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

	vector<int> D(K, 0);

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





	set<int> d; d.clear();

	rep (i, K) d.insert(D[i]);

	int res = 0;

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

		if (is_ok(i, d)){

			res = i;

			break;

		} // end if

	} // end for



	cout << res << endl;



	return 0;

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

#include <vector> 

#include <string> 

#include <algorithm>

#include <functional>

using namespace std;



int main() {

	int item_price;

  	string item_price_s;

  	int item_price_s_len;

  	int hate_num_cnt;



  	bool iroha_ng = true;

  	vector<int> hate_num;

  

  	cin >> item_price >> hate_num_cnt;

  

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

		int input;

      	cin >> input;

      	hate_num.push_back(input);

    }

  



  	while (iroha_ng || item_price > 90000) {

next_price:

		iroha_ng = false;

		item_price_s = to_string(item_price);

  		item_price_s_len = item_price_s.length();

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

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

				if ((item_price_s[j]-'0') == hate_num[i]) {

              		item_price++;

              		iroha_ng = true;

                  	goto next_price;

            	}

        	}

      	}

    }

  

  	cout << item_price;

}

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

#include <vector>

#include <algorithm>



using namespace std;



int main() {

	int item_price;

	int n;

	int hate_num_cnt;

	bool iroha_ng = true;



	cin >> item_price >> hate_num_cnt;

	vector<int> hate_num(hate_num_cnt);



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

		cin >> hate_num.at(i);

	}



	while (iroha_ng || item_price > 90000) {

		int n = item_price;

		iroha_ng = false;



		while (n != 0) {

			if (count(hate_num.begin(), hate_num.end(), n%10)) {

				item_price++;

				iroha_ng = true;

				break;

			}

			n=n/10;

        }

    }



	cout << item_price;

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

using namespace std;

#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)



int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);



  int N, K, k;

  cin >> N >> K;

  set<int> set;

  rep(i, 0, 10) { set.insert(i); }



  rep(i, 0, K) {

    cin >> k;

    set.erase(k);

  }



  bool ok;

  int ans = N;



  while (true) {

    string str = to_string(ans);

    ok = true;

    rep(i, 0, str.size()) {

      if (!set.count(str[i] - '0')) {

        ok = false;

        break;

      }

    }

    if (ok) {

      cout << ans << endl;

      break;

    }

    ans++;

  }

  getchar();

}

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

using namespace std;

#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)



map<int, bool> m;



bool chk(int n) {

  while (n) {

    if (m[n % 10]) {

      return false;

    }

    n /= 10;

  }

  return true;

}



int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);



  int N, K, k;

  cin >> N >> K;

  rep(i, 0, K) {

    cin >> k;

    m[k] = true;

  }



  while (true) {

    if (chk(N)) {

      cout << N << endl;

      break;

    }

    N++;

  }



  getchar();

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

using namespace std;

#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)



int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);



  int N, K, k;

  cin >> N >> K;

  set<int> set;

  rep(i, 0, 10) { set.insert(i); }



  rep(i, 0, K) {

    cin >> k;

    set.erase(k);

  }



  bool ok;

  int ans = N;



  while (N < 10001) {

    string str = to_string(ans);

    ok = true;

    rep(i, 0, str.size()) {

      if (!set.count(str[i] - '0')) {

        ok = false;

        break;

      }

    }

    if (ok) {

      cout << ans << endl;

      break;

    }

    ans++;

  }

  getchar();

}

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

using namespace std;

#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)



map<int, bool> m;



bool chk(int n) {

  while (n) {

    if (m[n % 10]) {

      return false;

    }

    n /= 10;

  }

  return true;

}



int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);



  int N, K, k;

  cin >> N >> K;

  rep(i, 0, K) {

    cin >> k;

    m[k] = true;

  }



  while (true) {

    if (chk(N)) {

      cout << N << endl;

      break;

    }

    N++;

  }



  getchar();

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

using namespace std;

#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)

 

int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);

 

  int N, K, k;

  cin >> N >> K;

  set<int> set;

  rep(i, 0, 10) { set.insert(i); }

 

  rep(i, 0, K) {

    cin >> k;

    set.erase(k);

  }

 

  bool ok;

  int ans = N;

 

  while (N < 10001) {

    string str = to_string(ans);

    ok = true;

    rep(i, 0, str.size()) {

      if (!set.count(str[i] - '0')) {

        ok = false;

        break;

      }

    }

    if (ok) {

      cout << ans << endl;

      break;

    }

    ans++;

  }

  getchar();

}

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

using namespace std;

#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)



map<int, bool> m;



bool chk(int n) {

  while (n) {

    if (m[n % 10]) {

      return false;

    }

    n /= 10;

  }

  return true;

}



int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);



  int N, K, k;

  cin >> N >> K;

  rep(i, 0, K) {

    cin >> k;

    m[k] = true;

  }



  while (true) {

    if (chk(N)) {

      cout << N << endl;

      break;

    }

    N++;

  }



  getchar();

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

using namespace std;

#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)

 

int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);

 

  int N, K, k;

  cin >> N >> K;

  set<int> set;

  rep(i, 0, 10) { set.insert(i); }

 

  rep(i, 0, K) {

    cin >> k;

    set.erase(k);

  }

 

  bool ok;

  int ans = N;

 

  while (ans < 100001) {

    string str = to_string(ans);

    ok = true;

    rep(i, 0, str.size()) {

      if (!set.count(str[i] - '0')) {

        ok = false;

        break;

      }

    }

    if (ok) {

      cout << ans << endl;

      break;

    }

    ans++;

  }

  getchar();

}

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

using namespace std;

#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)



map<int, bool> m;



bool chk(int n) {

  while (n) {

    if (m[n % 10]) {

      return false;

    }

    n /= 10;

  }

  return true;

}



int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);



  int N, K, k;

  cin >> N >> K;

  rep(i, 0, K) {

    cin >> k;

    m[k] = true;

  }



  while (true) {

    if (chk(N)) {

      cout << N << endl;

      break;

    }

    N++;

  }



  getchar();

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

using namespace std;



using ll = long long;



int N, K;

int D[11];



int main() {

   cin >> N >> K;

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

      cin >> D[i];

   }



   ll num = N;

   while (1) {

      string s = to_string(num); // 数字を文字列にする



      bool ok = true; // 嫌いな数字が存在しないならtrue

      // 嫌いな数字の有無を判定

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

         if (count(s.begin(), s.end(), D[i]+'0')) {

            ok = false;

            num++;

            break;

         }

      }



      // 嫌いな数字が無ければnumを出力して終了

      if (ok) {

         cout << num << endl;

         return 0;

      }

   }



   return 0;

}

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

#include <bits/stdc++.h>

#include<vector>



using namespace std;



int main(){

  int k,n;

  int d[10]={};



  cin>>n>>k;

  int temp;

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

    cin>>temp;

    d[temp]=1;

  }



int ans,num=n;

  ans=num;

  while(1){

    num=ans;

      while(num>0){

        if(d[num%10])break;

        num/=10;

      }

      if(num==0)break;

      ans++;

  }



  cout<<ans<<endl;





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

using namespace std;

typedef long long ll;



int main() {

    int n, k;

    cin >> n >> k;

    vector<int> d(k);

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

        cin >> d[i];

    }

    int ans = n;

    while(1){

        bool flag = true;

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

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

                if(to_string(ans)[i] - '0'== d[j]){

                    flag = false;

                    break;

                }

            }

            if(flag == false){

                break;

            }

        }

        if(flag){

            break;

        }else{

            ans++;

        }

    }

    cout << ans << endl;

    return 0;

}

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

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

#define chmin(x,y) x = min(x,y)

#define chmax(x,y) x = max(x,y)

using namespace std;

using Graph = vector<vector<int>>;

typedef long long ll;

typedef pair<int, int> P;

const int inf = INT_MAX;

const ll INF = 1LL << 60;

const ll mod = 1e9+7;

const int dx[4] = {-1, 0, 1, 0};

const int dy[4] = {0, -1, 0, 1};



// 042C



int main(){

    int n, k;

    cin >> n >> k;

    vector<int> d(k);

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

    vector<int> s(9);

    iota(s.begin(), s.end(), 0);

    vector<int>  ss;

    set_difference(s.begin(), s.end(), d.begin(), d.end(), back_inserter(ss));

    int ans = n;

    bool flag = true;



    while(flag){

        string tmp = to_string(ans);

        int nn = tmp.size();

        flag = false;

        rep(i, nn){

            rep(j, d.size()){

                if(tmp[i]-'0' == d[j]){

                    flag = true;

                    break;

                }

            }

            if(flag) break;

        }

        if(!flag) break;

        ans++;

    }

    cout << ans << endl;

    return 0;

}