stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

#define repr(i, a, b) for (int i = a; i < b; i++)

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

#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)

#define invrep(i, n) invrepr(i, 0, n)

const int MOD = 1e9 + 7;



int main()

{

    int n, k;

    cin >> n >> k;

    vector<int> use;

    vector<int> d(k);

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

    sort(d.begin(), d.end());

    int m = 0;

    rep(i, 10)

    {

        if (i != d[m])

            use.push_back(i);

        else

            ++m;

    }

    int ans;

    repr(i,n,100000) {

        int j = i;

        vector<int> value;

        while(j>0) {

            value.push_back(j%10);

            j/=10;

        }

        bool flag = 1;

        rep(j,value.size()) {

            bool flag1 = 0;

            rep(l,use.size()) {

                if (value[j]==use[l]) flag1=1;

            }

            if (!flag1) flag=0;

        }

        if (flag) {

            ans=i;

            break;

        }

    } 

    cout << ans << endl;

}

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

typedef long long ll;

using namespace std;

#define repr(i,a,b) for(int i=a;i<b;i++)

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

#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)

#define invrep(i,n) invrepr(i,0,n)

#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)

#define P pair<int,int>

const int MOD=998244353;

const ll INF=2e15;

const double PI=acos(-1);





int main() {

    ios_base::sync_with_stdio(false); 



    ll n,k;

    cin >> n >> k;

    vector<int> d(k);

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

    sort(d.begin(),d.end());

    int ans=0;

    repr(i,n,n+1000000) {

        bool flag=1; 

        int j=i;

        while (j>0) {

            int l=j%10;

            bool okay=1;

            rep(m,k) {

                if (l==d[m]) okay=0;

            }

            if (!okay) {

                flag=0;

                break;

            }

            j/=10;

        }

        if (flag) {

            ans=i;

            break;

        }

    }

    cout << ans << endl;





    return 0;

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

#include <vector>

#include <unordered_set>

#include <string>



#include <algorithm>



using namespace std;



using us = unordered_set<int>;



int main() {

	int n, k;

	cin >> n >> k;

	us availables = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};



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

		int num; cin >> num;

		availables.erase(num);

	}



	while(true) {

		string num = to_string(n);

		bool found = false;

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

			if(availables.find(num[i] - '0') == availables.end()) {

				break;

			}

			if(i == num.size() - 1) {

				found = true;

			}

		}

		if(found) {

			break;

		} else {

			n++;

		}

	}

	cout << n << endl;

}

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

#include <bitset>

#include <cmath>

#include <iostream>

#include <limits>

#include <list>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>



using namespace std;

using ll = long long;

const int IINF = 1e9;

const ll INF = 1e18;

const int MOD = 1e9 + 7;



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

#define YES(n) cout << ((n) ? "YES" : "NO") << endl



template <typename T>

void dumpvec(vector<T> vec) {

  for (T cnt : vec) {

    cout << cnt << ", ";

  }

  cout << endl;

}



void chmin(ll &a, ll b) {

  if (a > b) {

    a = b;

  }

}

void chmax(ll &a, ll b) {

  if (a < b) {

    a = b;

  }

}



vector<string> split(string s, string delimiter) {

  int first = 0;

  int last = s.find_first_of(delimiter);

  vector<string> result;



  while (first < s.size()) {

    string sub = s.substr(first, last - first);

    result.push_back(sub);

    first = last + 1;

    last = s.find_first_of(delimiter, first);



    if (last == string::npos) {

      last = s.size();

    }

  }



  return result;

}



string join(vector<string> strings, string delimiter) {

  string result = "";

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

    if (result != "") result += delimiter;

    result += strings[i];

  }

  return result;

}



class Solution {

 public:

  void solve() {

    int N, K;

    cin >> N >> K;

    set<int> availables{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

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

      int n;

      cin >> n;

      availables.erase(n);

    }

    while (true) {

      // dump(N);

      if (satisfy(N, availables)) {

        cout << N << endl;

        return;

      }

      N++;

    }

  }



  bool satisfy(int n, set<int> &availables) {

    if (n == 0) {

      return availables.count(0) > 0;

    }



    while (n > 0) {

      int digit = n % 10;

      if (availables.count(digit) == 0) return false;

      n /= 10;

    }

    return true;

  }

};



int main() { Solution().solve(); }
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <set>

#include <vector>



namespace {



typedef std::vector<int> IntVector;



/**

 * return degit length

 * It will return 1 if val is 0

 */

int degit_length(int val) {

  int length = 1;

  val /= 10;

  while (val) {

    length += 1;

    val /= 10;

  }



  return length;

}



int pow10(int n) {

  int res = 1;

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

    res *= 10;

  }



  return res;

}



IntVector slice_degit(int val) {

  IntVector iv;



  iv.push_back(val % 10);

  for (int i = 1; i < degit_length(val); ++i) {

    iv.push_back((val / pow10(i)) % 10);

  }



  return iv;

}



} // namespace



int main() {

  std::cin.tie(nullptr);

  std::ios::sync_with_stdio(false);



  int n, k;



  std::cin >> n >> k;



  int ki[10];

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

    ki[i] = 0;

  }



  int t;

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

    std::cin >> t;

    ki[t] = 1;

  }



  int res = n;

  for (;;) {

    IntVector iv = slice_degit(res);

    bool is_ng = false;

    for (auto v : iv) {

      if (ki[v]) {

        is_ng = true;

        break;

      }

    }



    if (!is_ng) {

      break;

    }

    ++res;

  }



  std::cout << res << std::endl;



  return 0;

}


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

#include <iostream>

#include <set>

#include <vector>



int main() {

  std::cin.tie(nullptr);

  std::ios::sync_with_stdio(false);



  int n, k;



  std::cin >> n >> k;



  int ki[10];

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

    ki[i] = 0;

  }



  int t;

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

    std::cin >> t;

    ki[t] = 1;

  }



  int res = n;

  for (;;) {

    if (ki[res % 10]) {

      ++res;

      continue;

    }



    int val = res / 10;

    bool is_ng = false;

    while (val != 0) {

      if (ki[val % 10]) {

        ++res;

        is_ng = true;

        break;

      }

      val /= 10;

    }

    if (!is_ng) {

      break;

    }

  }



  std::cout << res << std::endl;



  return 0;

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

#include <vector>

#include <cmath>

#include <string>

#include <algorithm>

using namespace std;

int main() {

  int n, k;

  vector<char> v;

  cin >> n >> k;

  while(k--) {

    char a;

    cin >> a;

    v.push_back(a);

  }

  int c = n;

  while (1) {

    bool bad = false;

    for (char d : to_string(c)) {

      for (char dc : v) {

        if (d == dc) {

          bad = true;

          c++;

          break;

        }

      }

      if (bad) {

        break;

      }

    }

    if (!bad) {

      break;

    }

  }

  cout << c << endl;

  return 0;

}

  


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

#include <vector>

#include <cmath>

#include <string>

#include <algorithm>

#include <numeric>

using namespace std;

// vector<int> v;

int n, ans, k, v[10];



bool valid() {

  int va = ans;

  while (va != 0) {

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

      int r = va % 10;

      if (r == v[i]) {

        return false;

      }

    }

    va /= 10;

  }

  return true;

}



int main() {

  cin >> k >> n;

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

    cin >> v[i];

  }

  ans = k;

  while (1) {

    if (valid()) {

      break;

    } else {

      ans++;

    }

  }

  cout << ans << endl;

  return 0;

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

#include <vector>

#include <cmath>

#include <string>

#include <algorithm>

using namespace std;

int main() {

  int n, k;

  vector<char> v;

  cin >> n >> k;

  while(k--) {

    char a;

    cin >> a;

    v.push_back(a);

  }

  int c = n;

  while (1) {

    bool bad = false;

    for (char d : to_string(c)) {

      for (char dc : v) {

        if (d == dc) {

          bad = true;

          c++;

          break;

        }

      }

      if (bad) {

        break;

      }

    }

    if (!bad) {

      break;

    }

  }

  cout << c << endl;

  return 0;

}

  


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

#include <vector>

#include <cmath>

#include <string>

#include <algorithm>

#include <numeric>

#include <climits>

#define LIM 1000007

#define ll long long

using namespace std;

bool v[10];

bool badnum(ll n) {

  int k = n;

  while (k != 0) {

    if (v[k % 10]) {

      return true;

    }

    k /= 10;

  }

  return false;

}

int main() {

  ll n, k;

  cin >> n >> k;

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

    int a;

    cin >> a;

    v[a] = true;

  }

  while (badnum(n)) {

    n++;

  }

  cout << n << endl;

  return 0;

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

#include <string>

#include <vector>

#include <algorithm>



using namespace std;



int main() {

    int N, K, D;

    int like[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};





    cin >> N >> K;



    for(int i = 0;i < K; ++i) { // 1 is considered true

        cin >> D;

        like[D] = 0; // dislike a number

    }



    int flag = false;

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

        string sN = to_string(i);

        for(int j = 0;j < sN.size(); ++j) { // per number like/not

            int indx = int(sN[j] - 48);

            if(like[indx] == 0) {

                break;

            } else if(j == sN.size() - 1) {

                flag = true;

            }

        }

        if(flag) {

            cout << i;

            break;

        }

    }



}


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

#include <string>

#include <vector>

#include <algorithm>



using namespace std;



int like[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};



int check(int x) {

    int y;

    while(x) {

        int y = x % 10;

        if(like[y] == false) {

            return false;

        }

        x /= 10;

    }

    return true;

}



int main() {

    int N, K, D;





    cin >> N >> K;



    for(int i = 0;i < K; ++i) { // 1 is considered true

        cin >> D;

        like[D] = 0; // dislike a number

    }



    int x, y;

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

        if(check(i)) {

            cout << i;

            break;

        }



    }



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

using namespace std;

int main() {

	int n, k;

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

	int d[k];

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

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

	bool used[10];

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

		used[i] = true;

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

		used[d[i]] = false;

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

		string s = to_string ( i );

		bool ok = true;

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

			if ( !used[s[j] - '0'] ) 

				ok = false;

		if ( ok ) {

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

			break;

		}

	}

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1540197291411958x):
#define _CRT_SECURE_NO_WARNINGS

#pragma _attribute_((optimize("-O2")))



#include <iostream>

#include <queue>

#include <stack>

#include <cstdio>

#include <vector>

#include <map>

#include <list>

#include <set>

#include <cstdio>

#include <bitset>

#include <algorithm>

#include <cmath>

#include <cstring>

#include <cstdlib>

#include <string>

#include <sstream>

#include <time.h>

#include <iomanip>



//#define Local



using namespace std;



set<int> dis;



bool chs(int in)

{

	bool flag = 1;

	while(flag&&in>0)

	{

		int tmp = in % 10;

		in /= 10;

		if (dis.count(tmp) != 0)

			flag = 0;

	}

	return flag;

}



int main()



{



	ios::sync_with_stdio(false);

	cin.tie(0);

	//freopen("input1.txt", "r", stdin);

	//freopen("output1.txt", "w", stdout);



	int t, k;

	while(cin>>t>>k)

	{

		dis.clear();

		while(k--)

		{

			int tmp;

			cin >> tmp;

			dis.insert(tmp);

		}

		while(1)

		{

			if(chs(t))

			{

				cout << t << endl;

				break;

			}

			t++;

		}

	}



#ifdef Local

	cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;

#endif

	return 0;

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

using namespace std;

int main() {

	int n, k;

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

	int d[k];

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

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

	bool used[10];

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

		used[i] = true;

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

		used[d[i]] = false;

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

		string s = to_string ( i );

		bool ok = true;

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

			if ( !used[s[j] - '0'] ) 

				ok = false;

		if ( ok ) {

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

			break;

		}

	}

	return 0;

}


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

#define Max(x,y) ((x)>(y)?(x):(y))  

#define Min(x,y) ((x)<(y)?(x):(y))  

#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)  

#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))  

#define ll long long  

#define Mem0(x) memset(x,0,sizeof(x))  

#define Mem1(x) memset(x,-1,sizeof(x))  

#define MemX(x) memset(x,0x3f,sizeof(x))  

#define pb push_back  

using namespace std;  

const int N=20;  

bool flag[N];  

  

int main(){  

  int k,i,x,j;  

  char n[N],s[N];  

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

    Mem0(flag);  

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

      scanf("%d",&x);  

      flag[x]=1;  

    }  

    int len=strlen(n),f1=0,f2=0;  

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

      if(f2){  

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

          if(flag[j]==0 && j>n[i]-'0'){  

            s[i]='0'+j;  

            n[i]=s[i];  

            break;  

          }  

        }  

        if(j==10){  

          if(!i){ f1=1; break; }  

          i-=2,f2=1;  

          continue;  

        }else{  

          f2=i;  

          break;  

        }  

      }  

      if(flag[n[i]-'0']){  

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

          if(flag[j]==0 && j>n[i]-'0'){  

            s[i]='0'+j;  

            n[i]=s[i];  

            break;  

          }  

        }  

        if(j==10){  

          if(!i){ f1=1; break; }  

          f2=1,i-=2;  

          continue;  

        }else{  

          f2=i;  

          break;  

        }  

      }else s[i]=n[i];  

    }  

    if(f1){  

      for(i=1;i<=9;++i)  

        if(flag[i]==0){  

          printf("%d",i);  

          break;  

        }  

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

        if(flag[i]==0){  

          while(len--)printf("%d",i);  

          break;  

        }  

    }else{  

      if(i==len)printf("%s",n);  

      else{  

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

          printf("%c",s[i]);  

        for(j=0;j<=9;++j)  

          if(flag[j]==0){  

            for(;i<len;++i)  

              printf("%d",j);  

            break;  

          }  

      }  

    }  

    puts("");  

  }  

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

using namespace std;

int main() {

	int n, k;

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

	int d[k];

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

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

	bool used[10];

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

		used[i] = true;

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

		used[d[i]] = false;

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

		string s = to_string ( i );

		bool ok = true;

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

			if ( !used[s[j] - '0'] ) 

				ok = false;

		if ( ok ) {

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

			break;

		}

	}

	return 0;

}


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

int n,k,a;

bool C[15];



bool Check(int x)

{

	char s[10];

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

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

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

			return false;

	return true;

}



int main()

{

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

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

	{

		scanf("%d",&a);

		C[a]=1;

	}

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

		if(Check(i))

		{

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

			break;

		}

	return 0;

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#pragma _attribute_((optimize("-O2")))



#include <iostream>

#include <queue>

#include <stack>

#include <cstdio>

#include <vector>

#include <map>

#include <list>

#include <set>

#include <cstdio>

#include <bitset>

#include <algorithm>

#include <cmath>

#include <cstring>

#include <cstdlib>

#include <string>

#include <sstream>

#include <time.h>

#include <iomanip>



//#define Local



using namespace std;



set<int> dis;



bool chs(int in)

{

	bool flag = 1;

	while(flag&&in>0)

	{

		int tmp = in % 10;

		in /= 10;

		if (dis.count(tmp) != 0)

			flag = 0;

	}

	return flag;

}



int main()



{



	ios::sync_with_stdio(false);

	cin.tie(0);

	//freopen("input1.txt", "r", stdin);

	//freopen("output1.txt", "w", stdout);



	int t, k;

	while(cin>>t>>k)

	{

		dis.clear();

		while(k--)

		{

			int tmp;

			cin >> tmp;

			dis.insert(tmp);

		}

		while(1)

		{

			if(chs(t))

			{

				cout << t << endl;

				break;

			}

			t++;

		}

	}



#ifdef Local

	cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;

#endif

	return 0;

}

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

int n,k,a;

bool C[15];



bool Check(int x)

{

	char s[10];

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

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

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

			return false;

	return true;

}



int main()

{

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

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

	{

		scanf("%d",&a);

		C[a]=1;

	}

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

		if(Check(i))

		{

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

			break;

		}

	return 0;

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

#define Max(x,y) ((x)>(y)?(x):(y))  

#define Min(x,y) ((x)<(y)?(x):(y))  

#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)  

#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))  

#define ll long long  

#define Mem0(x) memset(x,0,sizeof(x))  

#define Mem1(x) memset(x,-1,sizeof(x))  

#define MemX(x) memset(x,0x3f,sizeof(x))  

#define pb push_back  

using namespace std;  

const int N=20;  

bool flag[N];  

  

int main(){  

  int k,i,x,j;  

  char n[N],s[N];  

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

    Mem0(flag);  

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

      scanf("%d",&x);  

      flag[x]=1;  

    }  

    int len=strlen(n),f1=0,f2=0;  

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

      if(f2){  

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

          if(flag[j]==0 && j>n[i]-'0'){  

            s[i]='0'+j;  

            n[i]=s[i];  

            break;  

          }  

        }  

        if(j==10){  

          if(!i){ f1=1; break; }  

          i-=2,f2=1;  

          continue;  

        }else{  

          f2=i;  

          break;  

        }  

      }  

      if(flag[n[i]-'0']){  

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

          if(flag[j]==0 && j>n[i]-'0'){  

            s[i]='0'+j;  

            n[i]=s[i];  

            break;  

          }  

        }  

        if(j==10){  

          if(!i){ f1=1; break; }  

          f2=1,i-=2;  

          continue;  

        }else{  

          f2=i;  

          break;  

        }  

      }else s[i]=n[i];  

    }  

    if(f1){  

      for(i=1;i<=9;++i)  

        if(flag[i]==0){  

          printf("%d",i);  

          break;  

        }  

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

        if(flag[i]==0){  

          while(len--)printf("%d",i);  

          break;  

        }  

    }else{  

      if(i==len)printf("%s",n);  

      else{  

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

          printf("%c",s[i]);  

        for(j=0;j<=9;++j)  

          if(flag[j]==0){  

            for(;i<len;++i)  

              printf("%d",j);  

            break;  

          }  

      }  

    }  

    puts("");  

  }  

}  

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

int n,k,a;

bool C[15];



bool Check(int x)

{

	char s[10];

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

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

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

			return false;

	return true;

}



int main()

{

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

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

	{

		scanf("%d",&a);

		C[a]=1;

	}

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

		if(Check(i))

		{

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

			break;

		}

	return 0;

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

using namespace std;

int main() {

	int n, k;

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

	int d[k];

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

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

	bool used[10];

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

		used[i] = true;

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

		used[d[i]] = false;

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

		string s = to_string ( i );

		bool ok = true;

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

			if ( !used[s[j] - '0'] ) 

				ok = false;

		if ( ok ) {

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

			break;

		}

	}

	return 0;

}


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

#include<algorithm>

#include<vector>

using namespace std;

int k,N;

bool vis[20];

bool Pan(int x)

{

	while(x>0) 

	{

		if(vis[x%10])

			return 0;

		x/=10;

	}

	return 1;

}

int main()

{

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

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

	{

		int x;

		scanf("%d",&x);

		vis[x]=1;

	}

	if(N==0&&vis[0])

	{

		printf("1");

		return 0;

	}

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

		if(Pan(i))

		{

			printf("%d",i);

			return 0;

		}

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#pragma _attribute_((optimize("-O2")))



#include <iostream>

#include <queue>

#include <stack>

#include <cstdio>

#include <vector>

#include <map>

#include <list>

#include <set>

#include <cstdio>

#include <bitset>

#include <algorithm>

#include <cmath>

#include <cstring>

#include <cstdlib>

#include <string>

#include <sstream>

#include <time.h>

#include <iomanip>



//#define Local



using namespace std;



set<int> dis;



bool chs(int in)

{

	bool flag = 1;

	while(flag&&in>0)

	{

		int tmp = in % 10;

		in /= 10;

		if (dis.count(tmp) != 0)

			flag = 0;

	}

	return flag;

}



int main()



{



	ios::sync_with_stdio(false);

	cin.tie(0);

	//freopen("input1.txt", "r", stdin);

	//freopen("output1.txt", "w", stdout);



	int t, k;

	while(cin>>t>>k)

	{

		dis.clear();

		while(k--)

		{

			int tmp;

			cin >> tmp;

			dis.insert(tmp);

		}

		while(1)

		{

			if(chs(t))

			{

				cout << t << endl;

				break;

			}

			t++;

		}

	}



#ifdef Local

	cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;

#endif

	return 0;

}

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

#include<algorithm>

#include<vector>

using namespace std;

int k,N;

bool vis[20];

bool Pan(int x)

{

	while(x>0) 

	{

		if(vis[x%10])

			return 0;

		x/=10;

	}

	return 1;

}

int main()

{

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

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

	{

		int x;

		scanf("%d",&x);

		vis[x]=1;

	}

	if(N==0&&vis[0])

	{

		printf("1");

		return 0;

	}

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

		if(Pan(i))

		{

			printf("%d",i);

			return 0;

		}

}