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

using namespace std;



#define int long long

#define pb push_back

#define f first

#define s second

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



#define fast ios::sync_with_stdio(0); cin.tie(0)



int32_t main(){

  

    int n,k; cin >> n >> k;

    bool dislike[11] = {false};

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

      int d; cin >> d;

      dislike[d] = true;

    }



    while(true){

      string s = to_string(n);

      bool found = true;

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

        if(dislike[s[i]-'0']){

          found = false;

          break;

        } 

      }

      if(found){

        cout << n;

        break;

      } 

      else n++;

    }



    return 0;

} 

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

using namespace std;



#define int long long

#define pb push_back

#define f first

#define s second

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



#define fast ios::sync_with_stdio(0); cin.tie(0)



int32_t main(){

  

    int n,k; cin >> n >> k;

    bool dislike[10] = {false};

    

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

      int d; cin >> d;

      dislike[d] = true;

    }



    string s = to_string(n);

    int maxx_digit;



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

      if(!dislike[i]) maxx_digit = i;

    }



    for(int i=0;i<s.size();i++) s[i] = maxx_digit + 48;



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

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

        if(!dislike[j]){

          char temp = s[i];

          // cout << "j " << j << '\n';

          s[i] = j + 48;

          if(stoi(s)<n){

            s[i] = temp;

          }

          else break;

          // cout << "s = " <<./a s << '\n';

        }

      }

    }



    if(stoi(s)<n){

      vector<char> min_digit;

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

        if(!dislike[i]&&min_digit.size()!=2){

          min_digit.pb(i+48);

        }

      }



      s = string(s.size()+1,min_digit[0]);

      // cout << s;

      if(min_digit[0]=='0') s[0] = min_digit[1];



    }



    cout << s;



    return 0;

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

#include <vector>

#include <string>

using namespace std;

int main(void){

    // Here your code !

    int n,k;

    cin >> n >> k;

    vector<int> d(10,0);

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

        int t;

        cin >> t;

        d[t] = 1;

    }

    

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

        string s = to_string(i);

        int j;

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

            if(d[s[j]-'0']){

                break;

            }

        }

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

        cout << i << endl;

        break;

        }

    }

}


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

#include <map>

#include <algorithm>

#include <string>

#include <vector> 

#include <numeric>

#include <cmath>

#include <queue>

#include <iomanip>

#include <functional>





#define CHMAX(a,b) a = std::max(a,b)

#define CHMIN(a,b) a = std::min(a,b)

#define CHABS(a) a = std::abs(a) 

#define COUT(a) std::cout << a << std::endl

#define CERR(a) std::cerr << a << std::endl

#define FOR(n) for(lli i = 0; i < n; i++)



using namespace std;

using lli = long long int;

using pll = pair<lli, lli>;

using tlll = tuple<lli, lli, lli>;

using vll = vector<lli>;



lli mod197 = 1000000007LL;

lli INF = 10000000000000;



// ax + by = gcd(a,b) 最大公約数

template< typename T >

T extgcd(T a, T b, T& x, T& y) {

	T d = a;

	if (b != 0) {

		d = extgcd(b, a % b, y, x);

		y -= (a / b) * x;

	}

	else {

		x = 1;

		y = 0;

	}

	return d;

}



lli D[10] = {};



int main(void) {



	lli N, K;

	cin >> N >> K;



	//N以上で制約を満たす最も小さい数

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

		lli t;

		cin >> t;

		D[t] = 1;

	}



	for (lli i = N; i <= 20 * N; i++) {

		lli t = i;

		bool f = true;

		while (t != 0) {

			if (D[t % 10]) {

				f = false;

				break;

			}

			t /= 10;

		}

		if (!f)

			continue;

		COUT(i);

		return 0;

	}







	return 0;

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

using namespace std;

int check(char s,int K,int D[]){

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

		char temp[2];

		temp[0] = D[i]+'0';

		if(s==temp[0]){

			return 0;

		}

	}

	return 1;

}

int main(void){

	int N,K;

	cin >> N >> K;

	int D[K];

	for(int i=0;i<K;i++)cin >> D[i];

	int ans = 0;

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

		//条件を満たしたら終了

		string tmp = to_string(i);

		int flag  =1;

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

			if(check(tmp[j],K,D)==0){

				flag=0;

			}

		}

		if(flag == 1){

			cout << i;

			return 0;

		}

	}

}

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

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

#define ll long long

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



const ll mod = 1e9+7;

const ll INF = 2*1e18;

const int inf = 1e9+7;



using namespace std;



int main(void){

	cin.tie(0);

	ios::sync_with_stdio(false);

	int N,K;

	cin >> N >> K;

	vector<bool> ok(10,1);

	int ans = N;

	rep(i,K){

		int a;

		cin >> a;

		ok[a] = 0;

	}

	bool ng = 1;

	ans = N-1;

	while(ng){

		ng = 0;

		ans++;

		int tmp = ans;

		while(tmp){

			int x = tmp%10;

			tmp/=10;

			if(ok[x]==0){

				ng=1;

				break;

			}

		}

	}

	cout << ans << endl;

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

#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

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

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

#define endl       '\n'

#define MAX        1000000

#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

typedef long long int ll;

using namespace std;



void __print(int x) {cerr << x;}

void __print(long x) {cerr << x;}

void __print(long long x) {cerr << x;}

void __print(unsigned x) {cerr << x;}

void __print(unsigned long x) {cerr << x;}

void __print(unsigned long long x) {cerr << x;}

void __print(float x) {cerr << x;}

void __print(double x) {cerr << x;}

void __print(long double x) {cerr << x;}

void __print(char x) {cerr << '\'' << x << '\'';}

void __print(const char *x) {cerr << '\"' << x << '\"';}

void __print(const string &x) {cerr << '\"' << x << '\"';}

void __print(bool x) {cerr << (x ? "true" : "false");}



template<typename T, typename V>

void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}

template<typename T>

void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}

void _print() {cerr << "]\n";}

template <typename T, typename... V>

void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}





const ll mod = 1e9+7;

const double eps = 1e-9;

const double pi = acos(-1);



void solve(){

    int k;

    int n;

    cin>>n>>k;

    bool arr[11];

    memset(arr,false,sizeof(arr));

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

        int t;

        cin>>t;

        arr[t]=true;

    }

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

        string ans=to_string(i);

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

            if(arr[ans[j]-'0'])goto E;

        }

        cout<<i<<"\n";break;E:;

    }

}











int main(){

    fastio

    int test=1;

    while(test--)

        solve();

    return 0;

}


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

typedef long long int ll;

using namespace std;



int n, k;

int d[10];

void solve(){

    cin >> n >> k;

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

        int  t;

        cin >> t;

        d[t] = 1;

    }

    bool fl = 1;

    auto ok = [&](int x) {

        while(x) {

            if(d[x%10])

                return 0;

            x/=10;

        }

        return 1;

    };

    while(fl) {

        if(ok(n))

            fl = 0;

        else 

            n ++;

    }

    cout << n << "\n";

}



int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    int t =1;

    while(t--)

        solve();

    return 0;

}
// Slower C++ solution:
// ------------------------------------

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

}


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

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

}




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

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

}


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

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

}


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

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

}


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

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

}

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

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

}

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

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

}

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

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

}

  

  

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

    }

  }

      

}