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

}




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

        }

    }

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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





}


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

}

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

    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;

}


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

using namespace std;

typedef long long ll;



int main() {

    int n, k;

    cin >> n >> k;

    int dis[256] {};

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

        char d;

        cin >> d;

        dis[d] = 1;

    }

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

        string s = to_string(i);

        int ok = 1;

        for (char c : s) {

            if (dis[c]) {

                ok = 0;

                break;

            }

        }

        if (ok) {

            cout << s << endl;

            break;

        }

    }

    return 0;

}

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

using namespace std;

typedef long long ll;



int main() {

    int n,k;

    cin>>n>>k;

    int no[10]{};

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

        int a;cin>>a;

        no[a]=1;

    }

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

        int t=i;

        int f=1;

        while (t) {

            if (no[t%10])

                f=0;

            t/=10;

        }

        if (f) {

            cout<<i<<endl;

            break;

        }

    }

    return 0;

}

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



using namespace std;

template <class T> string toStr(T par) {

	ostringstream oss;

	oss<<par;

	return oss.str();

}

string s;

int n, k, q, dislikes[11];

int main()

{

    cin >> n >> k;

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

    {

        cin >> q;

        dislikes[q] = 1;

    }



    while(true)

    {

        int prev_n = n, cnt = 0;

        bool ok = false;

        s = toStr(n);

        for(int i = s.size() - 1; i >= 0; i--)

        {

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

                ok = true;

        }

        if(ok) n++;

        else break;

    }

    cout << n << endl;

    return 0;

}


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

#include<algorithm>

using namespace std;

int a,vis[66],n,k;

bool check(int x)

{

	while(x)

	{

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

		x/=10;

	}

	return 1;

}

int main()

{

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

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

	{

		scanf("%d",&a);

		vis[a]=1;

	}

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

	{

		if(check(i))

		{

			printf("%d",i);

			break;

		}

	}

}

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

#include<algorithm>

using namespace std;

bool num[10];

int a,b,c,l,n,k;

int main()

{

	cin>>n>>k;

	int cnt=0;

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

    {

        int a;

        cin>>a;

        num[a]=true;

    }

    int i=n;

    for(;;i++)

    {

        int t=i;

        int flog=1;

        for(;t;t/=10)

        {

            if(num[t%10])

            {

                flog=0;

                break;

            }

        }

        if(flog)

            break;

    }

    cout<<i<<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<bits/stdc++.h>



using namespace std;



int main()

{

	int N,k;

	cin>>N>>k;

	int d[10];

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

		cin>>d[i];

	int n=N;

	int flag;

	int h=N;

	while(1)

	{

		flag=1;

		while(n)

		{

			int r=n%10;

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

			{

				if(d[i]==r)

				{

					flag=0;

					break;

				}

			}

			n=n/10;

			if(flag==0)

			{

				break;

			}

		}

		if(flag==1)

		{

			cout<<h<<endl;

			break;

		}

		else{

			h++;

			n=h;

		}

	}

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>

using namespace std;

int sign[10]={0};

int main()

{

	int N,K,t=0,a,flag;

	cin>>N>>K;

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

	{

		cin>>a;

		sign[a]=1;

	}

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

	{

		int j=i;

		flag=1;

		while(j)

		{

			if(sign[j%10]==1)

			{

				flag=0;

				break;

			}	

			j=j/10;

		}

		if(flag==1)

		{

			cout<<i<<endl;

			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<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

#define ll long long

#define Di 3.1415926

#include<math.h>

#include<string>

#include<set>

#define INF 0x3f3f3f3f

using namespace std;

ll  gcd(ll a,ll b)

{

    return a%b? gcd(b,a%b):b;

}

int a[200];

int s[100];

 bool judge(int i)

 {

     while(i)

     {

         int t=i%10;

            if(s[t])

            {

                return false;

            }

            i/=10;

     }

     return true;

 }

int main()

{

     int m,i;

     int n;

     cin>>m>>n;

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

     {

         cin>>a[i];

          s[a[i]]=1;



     }

     for(i=m;;i++)

     {

          if(judge(i))

          {

            cout<<i<<endl;

              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<stdio.h>

#include<iostream>

#include<string>

#include<algorithm>

using namespace std;

int main()

{

    int n,m;

    while(cin>>n>>m)

    {

        int k;

        int vis[12]={0};

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

        {

            cin>>k;

            vis[k]=1;

        }

        while(1)

        {

            int flag=1;

            k=n;

            while(k)

            {

                int t =k%10;

                if(vis[t])

                {

                    flag=0;

                    break;

                }

                k/=10;

            }

            if(flag)

            {

                cout<<n<<endl;

                break;

            }

            n++;

        }

    }

    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: