/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

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

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}


int n , k ; 
bool mark [ 10 ] ;

bool ok ( int x ) {
	while ( x ) {
		if ( mark [ x % 10 ] ) return 0 ;
		x /= 10 ; 
	}
	return 1 ; 
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k ;
	for ( int i = 0 ; i < k ; ++ i ) {
		int p ;
		cin >> p ;
		mark [ p ] = 1 ; 
	}
	while ( n ) {
		if ( ok ( n ) )
			return cout << n << '\n' , 0 ;
		++ n ; 
	}
}
