stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<cstdio>

#include<vector>

#include<cstdlib>

#include<iostream>

using namespace std;

struct Node{

Node *parent,*left,*right;

int key;

};

Node *NIL,*root;

Node *find(Node*u,int k){

   while(u!=NIL&&k!=u->key){

    if(k<u->key)u=u->left;

    else u=u->right;

   }

   return u;

}



void prin_in(Node* node){

    if(node==NIL)return;

    prin_in(node->left);

    printf(" %d",node->key);

    prin_in(node->right);

}

void prin_pre(Node* node){

    if(node==NIL)return;

    printf(" %d",node->key);

    prin_pre(node->left);

    prin_pre(node->right);



}

void insert(int key)

{

    Node *y=NIL;

    Node *x=root;

    Node *z;

    z=(Node*)malloc(sizeof(Node));

    z->key=key;

    z->left=NIL;

    z->right=NIL;

    while(x!=NIL){

        y=x;

        if(z->key<x->key)

           x=x->left;

        else

            x=x->right;

    }

    z->parent=y;

    if(y==NIL){

        root=z;

    } else{

            if(z->key<y->key)

                y->left=z;

            else {

                y->right=z;

            }

    }

}

int main(){

   int n,i,x;

   string s;

   scanf("%d",&n);

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

   {

       cin>>s;

       if(s[0]=='i'){

        scanf("%d",&x);

        insert(x);

       }

       else if(s[0]=='f'){

        scanf("%d",&x);

        Node*t=find(root,x);

        if(t!=NIL)printf("yes\n");

        else printf("no\n");

       }

       else if(s[0]=='p'){

       prin_in(root);

       printf("\n");

       prin_pre(root);

       printf("\n");

       }

   }

   return 0;

}

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

#define N 500005

struct mzls

{

	int key;

	mzls *ch[2];

};

mzls tree[N];

bool f1=1;

mzls *root,*NIL,*ncnt;

inline void Init()

{

	NIL=&tree[0];

	NIL->ch[0]=NIL->ch[1]=NIL;

	ncnt=&tree[1];

	root=NIL;

}

inline mzls *newnode(int ml)

{

	mzls *p=++ncnt;

	p->key=ml;

	p->ch[0]=p->ch[1]=NIL;

	return p;

}

inline void Insert(mzls *&rt,int ml)

{

	if(rt==NIL)

	{

		rt=newnode(ml);

		return;

	}

	int d=(ml>=rt->key);

	Insert(rt->ch[d],ml);

}

inline void InOrder(mzls *rt)

{

	if(rt==NIL)

		return;

	InOrder(rt->ch[0]);

	printf(" %d",rt->key);

	InOrder(rt->ch[1]);

}

inline void Preorder(mzls *rt)

{

	if(rt==NIL)

		return;

	printf(" %d",rt->key);

	Preorder(rt->ch[0]);

	Preorder(rt->ch[1]);

}

inline mzls *Find(mzls *rt, int ml) 

{

	if(rt==NIL) return NIL;

	if(rt->key==ml) return rt;

	int d=(ml>=rt->key);

	return Find(rt->ch[d],ml);

}

int main()

{

	int n,x;

	char op[100];

	Init();

	scanf("%d",&n);

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

	{

		scanf("%s",op);

		if(op[0]=='i')

		{

			scanf("%d",&x);

			Insert(root,x);

		}

		else if(op[0]=='f') 

		{

			scanf("%d", &x);

			mzls *p=Find(root, x);

			if(p==NIL)

				puts("no");

			else

				puts("yes");

		}

		else

		{

			InOrder(root);

			puts("");

			Preorder(root);

			puts("");

		}

	}

	return 0;

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

using namespace std;

struct Node{

	int data;

	Node *left;

	Node *right;

	Node(int val=0){

		data=val;

		left=NULL;

		right=NULL;

	}

};

Node *root;

void insert(Node *&root,int x){

	if(root==NULL){

		root=new Node(x);

		return;

	}

	else{

		if(x==root->data) return;

		else if(x<root->data) insert(root->left,x);

		else insert(root->right,x);

	}

	return;

}

void Inorder(Node *node){

	if(node==NULL) return;

	Inorder(node->left);

	cout<<' '<<node->data;

	Inorder(node->right);

}

void Preorder(Node *node){

	if(node==NULL) return;

	cout<<' '<<node->data;

	Preorder(node->left);

	Preorder(node->right);

}

bool find(Node *&root,int x){

	if(root==NULL) return false;

	if(root->data==x) return true;

	else if(root->data<x){

		return find(root->right,x);

	}

	else{

		return find(root->left,x);

	}

}

int main(){

	root=NULL;

	int m;

	cin>>m;

	while(m--){

		string str;

		cin>>str;

		if(str[0]=='i'){

			int data;

			cin>>data;

			insert(root,data);

		}

		else if(str[0]=='f'){

			int data;

			cin>>data;

			if(find(root,data)) cout<<"yes"<<endl;

			else cout<<"no"<<endl;

		}

		else{

			Inorder(root);

			cout<<endl;

			Preorder(root);

			cout<<endl;

		}

	}

} 

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

#define N 500005

struct mzls

{

	int key;

	mzls *ch[2];

};

mzls tree[N];

bool f1=1;

mzls *root,*NIL,*ncnt;

inline void Init()

{

	NIL=&tree[0];

	NIL->ch[0]=NIL->ch[1]=NIL;

	ncnt=&tree[1];

	root=NIL;

}

inline mzls *newnode(int ml)

{

	mzls *p=++ncnt;

	p->key=ml;

	p->ch[0]=p->ch[1]=NIL;

	return p;

}

inline void Insert(mzls *&rt,int ml)

{

	if(rt==NIL)

	{

		rt=newnode(ml);

		return;

	}

	int d=(ml>=rt->key);

	Insert(rt->ch[d],ml);

}

inline void InOrder(mzls *rt)

{

	if(rt==NIL)

		return;

	InOrder(rt->ch[0]);

	printf(" %d",rt->key);

	InOrder(rt->ch[1]);

}

inline void Preorder(mzls *rt)

{

	if(rt==NIL)

		return;

	printf(" %d",rt->key);

	Preorder(rt->ch[0]);

	Preorder(rt->ch[1]);

}

inline mzls *Find(mzls *rt, int ml) 

{

	if(rt==NIL) return NIL;

	if(rt->key==ml) return rt;

	int d=(ml>=rt->key);

	return Find(rt->ch[d],ml);

}

int main()

{

	int n,x;

	char op[100];

	Init();

	scanf("%d",&n);

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

	{

		scanf("%s",op);

		if(op[0]=='i')

		{

			scanf("%d",&x);

			Insert(root,x);

		}

		else if(op[0]=='f') 

		{

			scanf("%d", &x);

			mzls *p=Find(root, x);

			if(p==NIL)

				puts("no");

			else

				puts("yes");

		}

		else

		{

			InOrder(root);

			puts("");

			Preorder(root);

			puts("");

		}

	}

	return 0;

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



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

using namespace std;



typedef long long ll;

struct pp{

	int key;

	pp *l, *r, *p; 

};



pp *root , *NIL;

pp * find(pp *x,int k){

	while(x != NIL &&k != x->key){

		if(k < x->key)

			x = x->l;

		else 

			x = x->r;

	}

	return x;

}



void insert (int k){

	pp *y=NIL;

	pp *x=root;

	pp *z;

	z = (pp *)malloc(sizeof(pp));

	

	z->key=k;

	z->l=NIL;

	z->r=NIL;

	

	

	while(x!=NIL){

		y=x;

		if(z->key < x->key){

			x=x->l;

		}

		else {

			x=x->r;

		}

	}

	

	z->p=y;

	if(y==NIL){

		root = z;

	}else 

		if(z->key < y->key){

			y->l = z;

		}

		else {

			y->r = z;

		}

}



void in(pp *x){

	if(x == NIL) return ;

	in(x->l);

	printf(" %d",x->key);

	in(x->r);

}



void pr(pp *x){

	if(x == NIL) return ;

	printf(" %d",x->key);

	pr(x->l);

	pr(x->r);

}

int main(){

	int n,x;

	string com;

	cin >> n;

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

		cin>>com;

		if(com[0] == 'f'){

			scanf("%d", &x);

			pp *t= find(root ,x );

			if(t != NIL)cout<<"yes\n";

			else printf("no\n");

		} 

		else if(com == "insert"){

			scanf("%d", &x);

			insert(x);

		}

		else if(com == "print"){

			in(root);

			cout<<endl;

			pr(root);

			cout<<endl;

		}

	}

	return 0;

}






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

#include <vector>

using namespace std;



typedef struct Node {

	int v;

	Node *l, *r;

	Node *p;

	Node() {

		this->v = 0;

		this->l = NULL;

		this->r = NULL;

		this->p = NULL;

	}

} Node, *pNode;



pNode root;



void InsertNode(const int& v);

pNode FindNode(pNode root, const int&v);



void PreOrder(pNode root);

void InOrder(pNode root);



int main()

{

	root = NULL;

	int T; scanf("%d",&T);

	while(T--) {

		char s[7]; scanf("%s",s);

		if(s[0] == 'p') {

			InOrder(root);

			putchar('\n');

			PreOrder(root);

			putchar('\n');

			continue;

		}

		int v; scanf("%d",&v);

		if(s[0] == 'i') {

			InsertNode(v);

		} else if(s[0] == 'f') {

			printf("%s\n",FindNode(root, v) != NULL?"yes":"no");

		} else if(s[0] == 'd') {

			//DeleteNode(FindNode(&root, v));

		}

	}

	return 0;

}



void PreOrder(pNode root)

{

	if(root == NULL) {

		return;

	}

	printf(" %d",root->v);

	PreOrder(root->l);

	PreOrder(root->r);

}



void InOrder(pNode root)

{

	if(root == NULL) {

		return;

	}

	InOrder(root->l);

	printf(" %d",root->v);

	InOrder(root->r);

}



void InsertNode(const int& v)

{

	pNode p = NULL, q = root;

	while(q != NULL) {

		p = q;

		if(v < q->v) {

			q = q->l;

		} else {

			q = q->r;

		}

	}

	pNode t = new Node;

	t->v = v;

	t->p = p;

	if(root == NULL) {

		root = t;

	} else {

		if(v < p->v) {

			p->l = t;

		} else {

			p->r = t;

		}

	}

}



pNode FindNode(pNode root, const int&v)

{

	while(root != NULL && root->v != v) {

		if(v < root->v) {

			root = root->l;

		} else {

			root = root->r;

		}

	}

	return root;

}
// Slower C++ solution:
/****************************

 * ×÷Õß£ºzxf

 * ÈÕÆÚ£º2017/8/8

 * ±êÌâ£º¤³¤À¤ï¤êÕß¤¤¤í¤Ï¤Á¤ã¤ó / Iroha's Obsession

 * ÌâºÅ£ºARC058C

 * ×öÌâ·½·¨£º...

 * ½á¹û£º

 * Time used£º

 * Memory used£º

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

#include <algorithm>

#include <bitset>

#include <cassert>

#include <cctype>

#include <cmath>

#include <complex>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <list>

#include <map>

#include <numeric>

#include <queue>

#include <set>

#include <sstream>

#include <stack>

#include <string>

#include <utility>

#include <vector>

#define LL long long

#define pb push_back

#define pob pop_back

#define mp make_pair

#define FILL(a,v) memset((void*)a,v,sizeof(a))

#define FILL0(a) FILL(a,0)

#define FILL1(a) FILL(a,-1)

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

#define Inf 1e9

#define Mod 1000000007

#define foreach(it,x) for(typeof(x.begin()) it=x.begin();it!=x.end();it++)

#define FOR(i,x) for(int i=0;i<x;i++)

#define RFOR(i,x) for(int i=x-1;i>=0;i--)

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

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

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

#define FI first

#define SE second

#define OVER(a) return puts(a),0

#define fastio ios::sync_with_stdio(0)

#define filei(f) freopen(f,"r",stdin)

#define fileo(f) freopen(f,"w",stdout)

using namespace std;

typedef pair<int,int> pii;

typedef unsigned long long UINT;

typedef unsigned int Uint;

typedef long long INT;

typedef pair<INT,INT> PII;

typedef stringstream sst;

typedef istringstream iss;

typedef vector<int> vint;

typedef vector<INT> VINT;

typedef vector<pii> vpii;

typedef vector<PII> VPII;

typedef priority_queue<int> pqi;

typedef priority_queue<INT> PQI;

typedef priority_queue<pii> pqp;

typedef priority_queue<PII> PQP;

typedef priority_queue<int,vint,greater<int> > xqi;

typedef priority_queue<INT,VINT,greater<INT> > XQI;

typedef priority_queue<pii,vpii,greater<pii> > xqp;

typedef priority_queue<PII,VPII,greater<PII> > XQP;



int n,m;

char s[10];

set<char> cant;



int main()

{

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

	int c;

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

	{

		scanf("%d",&c);

		cant.insert(c+'0');

	}

	while(1)

	{

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

		int can=1;

		for(int i=0;i<strlen(s);i++)

			if(cant.count(s[i]))

				can=0;

		if(can==1)return printf("%d\n",n),0;

		n++;

	}

}

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

#include <math.h>

#define MAX_N 10000

#define MAX_k 9

int N, k;

int D[MAX_k];

int check(int a){

    int i, j, n, m;

n=a;

while(n!=0){

        m = n%10;

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

            if (m==D[j]) return 1;

            n/=10;

}

    return 0;

}

int main(){

    int i;

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

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

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

    i=N;

    while (1)

    {

        if(check(i)==0)break;

        else

        {

            i++;

        }

    }

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

    return 0;

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

#include <set>

#include <cstring>

using namespace std;

 

int n,k;

set<int> dlike;

 

inline bool ok(int x)

{

	while(x>0)

	{

		if(dlike.count(x%10)) return 0;

		x/=10;

	}

	return 1;

}

 

int main()

{

	cin>>n>>k;

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

	{

		int a;

		cin>>a;

		dlike.insert(a);

	}

	

	for(int i=n;i<100000;i++) if(ok(i)) {cout<<i;exit(0);}

}

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

#include <math.h>

#define MAX_N 10000

#define MAX_k 9

int N, k;

int D[MAX_k];

int check(int a){

    int i, j, n, m;

n=a;

while(n!=0){

        m = n%10;

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

            if (m==D[j]) return 1;

            n/=10;

}

    return 0;

}

int main(){

    int i;

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

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

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

    i=N;

    while (1)

    {

        if(check(i)==0)break;

        else

        {

            i++;

        }

    }

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

    return 0;

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

#include <cstdlib>

#include <cstring>

#include <algorithm>

#include <iostream>

using namespace std;



int n, k;

bool dislike[10];



inline bool Check(int x) {

  do {

    if (dislike[x % 10])

      return false;

  } while (x /= 10);

  return true;

}



int main() {

  ios::sync_with_stdio(false);

  cin >> n >> k;

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

    cin >> x;

    dislike[x] = true;

  }

  for (; n; ++n) {

    if (Check(n)) {

      cout << n << endl;

      break;

    }

  }

  return 0;

}

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

#include <math.h>

#define MAX_N 10000

#define MAX_k 9

int N, k;

int D[MAX_k];

int check(int a){

    int i, j, n, m;

n=a;

while(n!=0){

        m = n%10;

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

            if (m==D[j]) return 1;

            n/=10;

}

    return 0;

}

int main(){

    int i;

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

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

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

    i=N;

    while (1)

    {

        if(check(i)==0)break;

        else

        {

            i++;

        }

    }

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

    return 0;

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

#include <vector>

#include <algorithm>

#include <fstream>

#include <iomanip>

#include <valarray>

#include <iterator>

#include <stack>

#include <set>

#include <cstring>

#include <cstdlib>

#include <queue>

#include <list>

#include <map>

#include <strstream>

#include <streambuf>

#include <string>

#include <sstream>



#define def(type,vec) vector<type> vec

#define last(arr) arr.size()-a

#define loop(i,n) for(ll i=0 ; i<n ; ++i)

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

#define pb push_back

#define ll long long

#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)



using namespace std;

string int_to_string(int x){

        string str;

        ostringstream temp;

        temp<<x;

        str=temp.str();

        return str;

}



int main(){

    int n,k;

    cin>>n>>k;

    char chr;

    set<char> st;

    loop(i,k){

        cin>>chr;

        st.insert(chr);

    }

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

        string str=int_to_string(i);

        bool x=true;

        loop(j,str.size()){

            if(binary_search(all(st),str[j])){

                x=false;

            }

        }

        if(x){

            cout<<i<<endl;

            break;

        }

    }

}




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

#include <math.h>

#define MAX_N 10000

#define MAX_k 9

int N, k;

int D[MAX_k];

int check(int a){

    int i, j, n, m;

n=a;

while(n!=0){

        m = n%10;

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

            if (m==D[j]) return 1;

            n/=10;

}

    return 0;

}

int main(){

    int i;

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

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

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

    i=N;

    while (1)

    {

        if(check(i)==0)break;

        else

        {

            i++;

        }

    }

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

    return 0;

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

using namespace std;

int dislike[11] = {0};

int solve(int test)

{

    int tt;

    while (test) {

        if (dislike[test % 10]) {

            return false;

        }

        test /= 10;

    }

    return true;

}

int main()

{

    int N, K;

    cin >> N  >> K;

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

        int t;

        cin >> t;

        dislike[t]++;

    }

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

        if (solve(i)) {

            cout << i << endl;

            break;

        }

    }

    return 0;

}


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

#include <math.h>

#define MAX_N 10000

#define MAX_k 9

int N, k;

int D[MAX_k];

int check(int a){

    int i, j, n, m;

n=a;

while(n!=0){

        m = n%10;

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

            if (m==D[j]) return 1;

            n/=10;

}

    return 0;

}

int main(){

    int i;

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

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

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

    i=N;

    while (1)

    {

        if(check(i)==0)break;

        else

        {

            i++;

        }

    }

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

    return 0;

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

using namespace std;

typedef long long ll;



int N, K;

int dis[10];



bool fnc(int num)

{

    while (num) {

        int rem = num % 10;

        if (dis[rem]) return false;

        num /= 10;

    }

    return true;

}



int dfs(int num)

{

    if (fnc(num)) return num;

    return dfs(num+1);

}



int main()

{

    cin >> N >> K;

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

        int tmp;

        cin >> tmp;

        dis[tmp] = 1;

    }



    cout << dfs(N);

}


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

#include <math.h>

#define MAX_N 10000

#define MAX_k 9

int N, k;

int D[MAX_k];

int check(int a){

    int i, j, n, m;

n=a;

while(n!=0){

        m = n%10;

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

            if (m==D[j]) return 1;

            n/=10;

}

    return 0;

}

int main(){

    int i;

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

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

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

    i=N;

    while (1)

    {

        if(check(i)==0)break;

        else

        {

            i++;

        }

    }

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

    return 0;

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

#include<algorithm>

#include<set>

using namespace std;



typedef long long int llt;



bool chk(int n,set<int> st)

{

	

	while(n!=0)

	{

		int dig=n%10;

		if(st.find(dig)!=st.end())

		return false;

		n/=10;

	}

	return true;



}



int main()

{

	llt n,k;

	cin>>n>>k;

	set<int> st;

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

	{

		int x;

		cin>>x;

		st.insert(x);

	}

	int res=n;

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

	{

		if(chk(i,st))

		{

			res=i;

			break;

		}

	}

	cout<<res<<endl;

	return 0;

	

}

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

#include <math.h>

#define MAX_N 10000

#define MAX_k 9

int N, k;

int D[MAX_k];

int check(int a){

    int i, j, n, m;

n=a;

while(n!=0){

        m = n%10;

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

            if (m==D[j]) return 1;

            n/=10;

}

    return 0;

}

int main(){

    int i;

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

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

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

    i=N;

    while (1)

    {

        if(check(i)==0)break;

        else

        {

            i++;

        }

    }

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

    return 0;

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

#include <bits/extc++.h>

using namespace __gnu_pbds;

using namespace std;

#define testing 1

#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)

#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)

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

#define db(x) cerr << #x << "=" << x << endl

#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl

#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl

#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl

#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl

#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long 

#define pb push_back

#define inf (int)1e9+500

#define oo (ll)1e18+500

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

#define f first

#define s second

#define reach cerr << "LINE: " << __LINE__ << "\n";

typedef pair <int, int> pi;

typedef pair <ll,ll> pl;

typedef pair <pi, int> pii;

typedef tuple<int,int,int> ti3;

string cts(char x) {string t(1,x); return t;}

ll rand(ll a, ll b) { return a + rng() % (b-a+1); }

const int MOD = 1e9 + 7;

template <typename T> void chmax(T& a, T b) {

	a = max(a, b);

}

template <typename T> void chmin(T& a, T b) {

	a = min(a, b);

}

#define MAXN

#if !testing

#define cerr if(0)cout

#endif



int32_t main() {

    IAMSPEED

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

    set<char>cannot;

    FOR(i,1,k) {

        int x; cin >> x;

        cannot.insert(x);

    }

    FOR(i,n,n*100) {

        string str = to_string(i);

        bool can = 1;

        for (auto it : str) {

            if(cannot.find(int(it-'0'))!=cannot.end())can = 0;

        }

        if(can) {

            cout<<i;

            return 0;

        }

    }

}


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

#include <math.h>

#define MAX_N 10000

#define MAX_k 9

int N, k;

int D[MAX_k];

int check(int a){

    int i, j, n, m;

n=a;

while(n!=0){

        m = n%10;

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

            if (m==D[j]) return 1;

            n/=10;

}

    return 0;

}

int main(){

    int i;

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

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

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

    i=N;

    while (1)

    {

        if(check(i)==0)break;

        else

        {

            i++;

        }

    }

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

    return 0;

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

using namespace std;

//#include<ext/rope>

//using namespace __gnu_cxx

//#include<ext/pb_ds/priority_queue.hpp>

//using namespace __gnu_pbds;

#define lowbit(x) (x&-x)

#define pb push_back

#define empb emplace_back

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

#define clr(a,b) memset(a,b,sizeof(a))

#define caze(T) for(cin>>T;T;T--)

#define inf (1<<29)

#define Endl ('\n')

#define fi first

#define se second

#define db double

#define ldb long double

#define ll long long

#define pii pair<int,int>

#define pil pair<int,ll>

#define pli pair<ll,int>

#define pll pair<ll,ll>

#define ull unsigned long long

#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

inline char nc() {

	#define SZ 1000000

	static char buf[SZ], *p1, *p2;

	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;

}

template<typename T>

inline int scan(T &x) {

	char c, sign=1; 

	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;

	if(c==EOF) return EOF;

	for(x = 0; isdigit(c); c = nc())

		x = (x<<1) + (x<<3) + (c&15);

	return x *= sign, 1;

}

template<typename T, typename...Args>

inline int scan(T &x, Args&...args) {

	return scan(x), scan(args...);

}

const int N=1<<14;

int v[N];

bool ok(int x)

{

	while(x)

	{

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

		x/=10;

	}

	return 1;

}

int main()

{IOS;

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

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

		cin>>x,v[x]=1;

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

		if(ok(i))

			return cout<<i<<Endl,0;

}

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

#include <math.h>

#define MAX_N 10000

#define MAX_k 9

int N, k;

int D[MAX_k];

int check(int a){

    int i, j, n, m;

n=a;

while(n!=0){

        m = n%10;

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

            if (m==D[j]) return 1;

            n/=10;

}

    return 0;

}

int main(){

    int i;

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

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

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

    i=N;

    while (1)

    {

        if(check(i)==0)break;

        else

        {

            i++;

        }

    }

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

    return 0;

}