stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
// ------------------------------------

// Date:2018/ 2/22

// Problem:ABC 042 Iroha's Obsession c.cpp

//

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



#include <bits/stdc++.h>



using namespace std;



#define EACH(i,a) for (auto&& i : a)

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

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

#define REP(i,n) FOR(i,0,n)

#define RREP(i,n) RFOR(i,0,n)

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



using ll = long long;



int main()

{

  int N,K;

  string t;

  cin >> N >> K;

  vector<int> L(K);

  REP(i,K) cin >> L[i];

  FOR(i,N,10*N) {

    bool flag = true;

    t = to_string(i);

    REP(j,t.size()) {

      REP(k,L.size()) {

        if (t[j]-'0' == L[k]) flag = false;

      }

    }

    if (flag) {

      cout << t << endl;

      return 0;

    }

  }

  cout << endl;

  

  return 0;

}


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



using namespace std;



#define EACH(i,a) for (auto& i : a)

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

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

#define REP(i,n) FOR(i,0,n)

#define RREP(i,n) RFOR(i,0,n)

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

#define debug(x) cerr << #x << ":" << x << endl;

#define OK(ok) cout << (ok ? "Yes" : "No") << endl;

typedef long long ll;



void CINT(){}

template <class Head,class... Tail>

void CINT(Head&& head,Tail&&... tail) {

  cin >> head; CINT(move(tail)...);

}

#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)

#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)

#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)



const int INF = 1e9 + 1;

const int MOD = 1e9 + 7;

const int MAX_N = 1e4 + 1;



bool check(int i, vector< int > D) {

  int tmp;

  while (i > 0) {

    if (i >= 10) {

      tmp = i % 10;

      REP(j, D.size()) {

	if (tmp == D[j]) {

	  return false;

	}

      }

      i /= 10;

    } else {

      REP(j, D.size()) {

	if (i == D[j]) {

	  return false;

	}

      }

      break;

    }

  }

  return true;

}



int main()

{

  cin.tie(0);

  ios::sync_with_stdio(false);



  CIN(N, K);

  vector< int > D(K);

  REP(i, K) {

    cin >> D[i];

  }



  FOR(i, N, INF) {

    if (check(i, D)) {

      cout << i << endl;

      break;

    }

  }



  return 0;

}




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



using namespace std;



#define EACH(i,a) for (auto& i : a)

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

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

#define REP(i,n) FOR(i,0,n)

#define RREP(i,n) RFOR(i,0,n)

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

#define debug(x) cerr << #x << ":" << x << endl;

#define OK(ok) cout << (ok ? "Yes" : "No") << endl;

typedef long long ll;



void CINT(){}

template <class Head,class... Tail>

void CINT(Head&& head,Tail&&... tail) {

  cin >> head; CINT(move(tail)...);

}

#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)

#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)

#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)



const int INF = 1e9 + 1;

const int MOD = 1e9 + 7;

const int MAX_N = 1e5 + 1;



bool able[10];

int N, K;



bool check(int n)

{

  string s = to_string(n);

  REP(i, s.size()) {

    if (able[s[i] - '0']) return false;

  }

  return true;

}



int main()

{

  cin.tie(0);

  ios::sync_with_stdio(false);



  cin >> N >> K;

  REP(i, K) {

    CIN(a);

    able[a] = true;

  }



  int tmp = N;

  while(true) {

    if(check(tmp)) break;

    tmp++;

  }



  cout << tmp << endl;

  

  return 0;

}




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



using namespace std;



#define EACH(i,a) for (auto& i : a)

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

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

#define REP(i,n) FOR(i,0,n)

#define RREP(i,n) RFOR(i,0,n)

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

#define debug(x) cerr << #x << ":" << x << endl;

#define OK(ok) cout << (ok ? "Yes" : "No") << endl;

typedef long long ll;



void CINT(){}

template <class Head,class... Tail>

void CINT(Head&& head,Tail&&... tail) {

  cin >> head; CINT(move(tail)...);

}

#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)

#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)

#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)



const int INF = 1e9 + 1;

const int MOD = 1e9 + 7;

const int MAX_N = 1e4 + 1;



bool check(int i, vector< int > D) {

  int tmp;

  while (i > 0) {

    if (i >= 10) {

      tmp = i % 10;

      REP(j, D.size()) {

	if (tmp == D[j]) {

	  return false;

	}

      }

      i /= 10;

    } else {

      REP(j, D.size()) {

	if (i == D[j]) {

	  return false;

	}

      }

      break;

    }

  }

  return true;

}



int main()

{

  cin.tie(0);

  ios::sync_with_stdio(false);



  CIN(N, K);

  vector< int > D(K);

  REP(i, K) {

    cin >> D[i];

  }



  FOR(i, N, INF) {

    if (check(i, D)) {

      cout << i << endl;

      break;

    }

  }



  return 0;

}




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

using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef vector<int> vint;

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

#define rep(i,n) FOR(i,0,n)

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

#define RALL(x) (x).rbegin(),(x).rend()

#define SZ(x) (int)(x).size()

#define SYAMU(ary) memset(ary,0,sizeof(ary))

#define dbg(x) cout<<#x<<": "<<(x)<<"\n"

#define pb push_back

#define eb emplace_back

#define mp make_pair



int n;

int k;

vector<char> D(12);



bool OK(string s) {

    rep(i, SZ(s)) {

        rep(j,k) {

            if(s[i] == D[j]) return false;

        }

    }

    return true;

}



int main() {

    while(cin>>n>>k) {

        D.clear();

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



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

            string s = to_string(i);

            if(OK(s)) {

                cout << i << "\n";

                goto koko;

            }

        }

koko:

        n += 0;

    }



    return 0;

}


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

using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef vector<int> vi;

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

#define rep(i,n) FOR(i,0,n)

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

#define RALL(x) (x).rbegin(),(x).rend()

#define SZ(x) (int)(x).size()

#define mset(a,x) memset(a,x,sizeof(a))

#define dbg(x) cout<<#x<<": "<<(x)<<"\n"

#define pb push_back

#define mp make_pair



int n, k;

vector<int> d;



bool ng(int x){

    while(x > 0){

        int a = x % 10;

        rep(i,k) if(a == d[i]) return true;

        x /= 10;

    }

    return false;

}



int main() {

    cin >> n >> k;

    d.resize(k);

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



    for(int i=n; ; ++i) if(!ng(i)) {

        cout << i << endl;

        return 0;

    }



    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 rrep(i,n) for(int i=1;i<(n);++i)

#define all(a) (a).begin(),(a).end()

#define rall(a) (a).rbegin(),(a).rend()

using namespace std;

typedef long long ll;

typedef pair<int, int> P;

const int inf = 1001001001;

const int mod = 1000000007;



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	int n, k;

	cin >> n >> k;

	vector<int> d(k);

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

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

		if (i < n) continue;

		vector<int> res;

		int tmp = i;

		while (tmp) {

			res.emplace_back(tmp % 10);

			tmp /= 10;

		}

		bool elf = true;

		for (auto& c : res) {

			rep(i, k) {

				if (c == d[i]) elf = false;

			}

		}

		if (elf) {

			cout << i << endl;

			break;

		}

	}

	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 rrep(i,n) for(int i=1;i<(n);++i)

#define all(a) (a).begin(),(a).end()

#define rall(a) (a).rbegin(),(a).rend()

#define maxs(a, b) a = max(a, b)

#define mins(a, b) a = min(a, b)

using namespace std;

typedef long long ll;

typedef pair<int, int> P;

const ll linf = (1ll << 61);

const int inf = 1001001001;

const int mod = 1000000007;



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	int n, k;

	cin >> n >> k;

	vector<int> rec(10);

	rep(i, k) {

		int d;

		cin >> d;

		rec[d] = 1;

	}

	while (1) {

		bool elf = true;

		int now = n;

		while (now) {

			if (rec[now % 10]) elf = false;

			now /= 10;

		}

		if (elf) {

			cout << n << endl;

			return 0;

		}

		n++;

		

	}

	return 0;

}

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

#include <vector>

#include <sstream>

#include <iterator>

#include <algorithm>

using namespace std;



int n, k;

vector<char> h;



int is_ok(int a) {

	stringstream ss;

	string s;

	vector<char> v;

	int len;



	ss << a;

	s = ss.str();

	len = s.length();

	v.resize(len);

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

		v[i] = s[i];

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

	v.erase(unique(v.begin(), v.end()), v.end());

	vector<char> w;

	set_intersection(h.begin(), h.end(), v.begin(), v.end(), back_inserter(w));



	return w.size();

}



int main(void) {

	cin >> n >> k;

	h.resize(k);

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

		cin >> h[i];



	int ans = 0;

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

		if (is_ok(i) == 0) {

			ans = i;

			break;

		}

	}



	cout << ans << '\n';

	return 0;

}


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

#include <string>

#include <sstream>

#include <vector>

using namespace std;



int main(void) {

	int N, K;

	stringstream ss;

	vector<bool> L;



	cin >> N >> K;

	L.resize(10, true);

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

		int d;

		cin >> d;

		L[d] = false;

	}



	int ans = -1;

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

		ss.str("");

		ss.clear();

		ss << i;

		string s = ss.str();

		bool flag = true;

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

			int num = (int)(s[j] - '0');

			if (L[num] == false) {

				flag = false;

				break;

			}

		}

		if (flag) {

			ans = i;

			break;

		}

	}



	cout << ans << '\n';

	return 0;

}


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

using namespace std;

bool d[10],f;

int main(){

	long long n,k,i,j;

	cin>>n>>k;

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

		cin>>j;

		d[j]=1;

	}

	string s;

	char c[10];

	for(i=0;i<=9;i++)c[i]='0'+i;

	for(i=n;i<=n*100;i++){

		stringstream ss;

		ss<<i;

		s=ss.str();

		f=1;

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

			if(d[j]&&s.find(c[j])!=-1){

				f=0;

				break;

			}

		}

		if(f){

			cout<<i<<'\n';

			break;

		}

	}

	return 0;

}

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

using namespace std;

long long n,k,i,j,t,book[20];

int main(){

	

	cin>>n>>k;

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

		cin>>t;

		book[t]=1;

	}

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

		long long x=i,f=0;

		while(x!=0){

			if(book[x%10]==1)f=1;

			x/=10; 

		}

		if(f==0){

			cout<<i;

			return 0;

		}

	}

	return 0;

}

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

using namespace std;

char d[10];

long long n,k,i,j;

int main(){

	cin>>n>>k;

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

		char f;

		cin>>f;

		d[f-'0']=1;

	}

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

		long long x=i;

		string s;

		stringstream ss;

		ss<<i;

		s=ss.str();

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

			//cout<<s;

			if(d[(s[j]-'0')]==1)break;

		}

		if(j==s.size()){

			cout<<x<<'\n';

			return 0;

		}

	}

	return 0;

}

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

using namespace std;

long long n,k,i,j,t,book[20];

int main(){

	

	cin>>n>>k;

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

		cin>>t;

		book[t]=1;

	}

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

		long long x=i,f=0;

		while(x!=0){

			if(book[x%10]==1)f=1;

			x/=10; 

		}

		if(f==0){

			cout<<i;

			return 0;

		}

	}

	return 0;

}

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

/****************************************************

https://searleser97.gitlab.io/algorithms/template.cpp

****************************************************/



#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define forr(_, x, n) for (int _ = x; _ > n; _--)

#define fos(_, x, n, s) for (int _ = x; _ < n; _ += s)

#define forn(_, x, n) fos(_, x, n, 1)

#define rep(_, n) forn(_, 0, n)

#define fi first

#define se second

#define pb push_back

#define pairii pair<int, int>

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

#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"

// typedef __int128_t lli;

typedef long long int li;

typedef long double ld;

// 12

void _main(int tc) {

  int n, k;

  cin >> n >> k;

  vector<bool> s(10);

  rep(i, k) {

    int x;

    cin >> x;

    s[x] = 1;

  }



  forn(i, n, (int) 1e6) {

    string str = to_string(i);

    bool flag = 0;

    for (auto& c : str) {

      if (s[c - '0']) {

        flag = 1;

        break;

      }

    }

    if (!flag) {

      cout << i << endl;

      return;

    }

  }

}



int main() {

  ios_base::sync_with_stdio(0), cin.tie(0);

  _main(0); return 0;

  int tc;

  cin >> tc;

  rep(i, tc) _main(i + 1);

}

// Optimized solution to the same problem (faster):
// 20

/****************************************************

https://searleser97.gitlab.io/algorithms/template.cpp

****************************************************/



#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define forr(_, x, n) for (int _ = x; _ > n; _--)

#define fos(_, x, n, s) for (int _ = x; _ < n; _ += s)

#define forn(_, x, n) fos(_, x, n, 1)

#define rep(_, n) forn(_, 0, n)

#define fi first

#define se second

#define pb push_back

#define pairii pair<int, int>

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

#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"

// typedef __int128_t lli;

typedef long long int li;

typedef long double ld;

// 12

void _main(int tc) {

  int n, k;

  cin >> n >> k;

  vector<bool> s(10);

  rep(i, k) {

    int x;

    cin >> x;

    s[x] = 1;

  }



  forn(i, n, (int) 1e6) {

    int aux = i;

    bool flag = 0;

    for(; aux; aux /= 10) {

      if (s[aux % 10]) {

        flag = 1;

        break;

      }

    }

    if (!flag) {

      cout << i << endl;

      return;

    }

  }

}



int main() {

  ios_base::sync_with_stdio(0), cin.tie(0);

  _main(0); return 0;

  int tc;

  cin >> tc;

  rep(i, tc) _main(i + 1);

}

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

using namespace std;



typedef long long ll;

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

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

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



int N, K, D[9];



bool check(int a){

  bool flag = true;

  string b = to_string(a);

  rep(i,b.size()){

    rep(j,K){

      if(a % 10 == D[j]) flag = false;

    }

    a = a/10;

  }

  return flag;

}



int main(){

  memset(D, -1, sizeof(D));

  cin >> N >> K;

  rep(i, K){

    int d;

    cin >> d;

    D[i] = d;

  }

  int ans = N;

  while(true){

    if(check(ans)){

      break;

    }

    ans++;

  }

  cout << ans <<endl;

}

  

  

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

using namespace std;

typedef long long ll;

typedef pair<int, int> P;

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

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

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

const int INF = 1e9 + 1;

const ll MOD = 1e9 + 7;

const double PI = 3.141592653589793;



int main(){

  int n, k;

  cin >> k >> n;

  bool d[10];

  fill(d, d+10, false);

  rep(i, n){

    int tmp;

    cin >> tmp;

    d[tmp] = true;

  }

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

    int tmp = i;

    bool flag = true;

    while(tmp){

      if(d[tmp%10]){

        flag = false;

        break;

      }

      tmp /= 10;

    }

    if(flag){

      cout << i <<endl;

      return 0;

    }

  }

      

}

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

#include <vector>

#include <algorithm>

#include <set>



using namespace std;



typedef long long i64;



set<int> D;

bool hate(i64);



int main(void) {

    i64 N, K;

    cin >> N >> K;



    int d, i;

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

        cin >> d;

        D.insert(d);

    }



    while (hate(N)) {

        N++;

    }



    cout << N << endl;



    return 0;

}





bool hate(i64 N) {

    int d;

    while (N) {

        d = N % 10;

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



        N /= 10;

    }

    return false;

}


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



using namespace std;



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

    while (N) {

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



        N /= 10;

    }

    return true;

}



int main() {

    int N, K;

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



    int D[10]={};

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

        int d;

        scanf("%d", &d);

        ++D[d];

    }



    while (!is_valid(D, N))

        ++N;



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

    return 0;

}


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

#include <set>



using namespace std;



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

    while (N) {

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



        N /= 10;

    }

    return true;

}



int main() {

    int N, K;

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



    set<int> D;

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

        int d;

        scanf("%d", &d);

        D.insert(d);

    }



    while (!is_valid(D, N))

        ++N;



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

    return 0;

}


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



using namespace std;



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

    while (N) {

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



        N /= 10;

    }

    return true;

}



int main() {

    int N, K;

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



    int D[10]={};

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

        int d;

        scanf("%d", &d);

        ++D[d];

    }



    while (!is_valid(D, N))

        ++N;



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

    return 0;

}


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

#include<algorithm>

using namespace std;

int N,k,a[20];

bool book[20];

bool Check(int i) {

	char s[20]={};

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

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

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

			return false;

	return true;

}

int main() {

	#ifdef LOACL

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

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

	#endif

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

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

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

		book[a[i]]=true;

	}

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

		if(Check(i)) {

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

			break;

		}

	return 0;

}

// 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<set>  

#include<map>  

#include<stack>  

#include<cmath>  

#include<cstdio>  

#include<queue>  

#include<vector>  

#include<cstring> 

#include<climits>  

#include<iostream> 

#include<algorithm> 

using namespace std; 

int read(){ 

    int f=1,x=0; 

    char c=getchar(); 

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

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

    return f*x; 

}

#define MAXN 300

#define INF 0x3f3f3f3f

int pan[100];

bool check(int x){

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

	while(x){

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

		x/=10;

	}

	return 1;

}

int main(){

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

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

		pan[read()]=1;

	while(1){

		if(check(n)){

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

			return 0;

		}

		n++;

	}

    return 0;

}

// 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 <cstring>

#include <string>

using namespace std;



int main(){

	int n,k;

	int x,m;

	int a[11];

	int ans[10];

	

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

	cin >> n >> k;

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

		cin >> x;

		a[x] = 0;

	}

	

	while(1){

	

		int i = 0;

		m = n;

		while(n){

			ans[i++] = n%10;

			n/=10;

		}

		int flag = 0;

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

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

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

					m++;

					n = m;

					flag = 1;

					break;

				}

			}

			if(flag){

				break;

			}

		}

		

		if(!n){

			break;

		}

	}

	cout << m;	

}

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

using namespace std;

int s[11];

 int ss[11];

int main()

{

int n,m;

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

 int x;

 int a;

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

 {

     cin>>a;

     s[a]=1;

 }

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

    if(i>=n)

 {

     int a;a=i;

     int k;k=0;

     while(a)

     {

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

         a=a/10;

     }

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



 }

}


// 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: