import std.stdio;

void main(){
	auto cin = new Cin();
	//auto j = new Joint();
	
	auto NK = cin.line();
	auto D = cin.line();
	
	auto N = NK[0];
	
	solve( N , D ).writeln();
	
	
}
auto solve( size_t n , size_t[] ng ){
	bool[10] nglist;
	nglist[] = true;
	
	foreach( elm ; ng ){
		nglist[elm] = false;
	}
	
	forD:foreach( i ; n..n+20_000 ){
		foreach( j ; 0..5 ){
			n = i%(10^^(j+1))/(10^^j);
			if( nglist[n] == false ){
				continue forD;
			}
		}
		return i;
	}
	return 0;
}
unittest{
	assert( solve(9999,[9]) == 10000 );
	assert( solve(5555,[5]) == 6000 );
	assert( solve(1111,[1,3,4,5,6,7,8,9]) == 2000 );
}


import std.stdio,std.conv,std.string;
import std.algorithm,std.array;

class Cin
{
	T[] line( T = size_t , string token = " " )( size_t m = 1 ){
		T[] arr = [];
		foreach( i ; 0..m ){
			arr ~= this.read!T();
		}
		return arr;
	}
	T[][] rect( T = real , string token = " " )( size_t m = 1 ){
		T[][] arr = new T[][]();
		foreach( i ; 0..m ){
			arr[i] = this.read!T(token);
		}
		return arr;
	}
	private T[] read( T = size_t )( string token = " " ){
		T[] arr;
		foreach( elm ; readln().chomp().split(token) ){
			arr ~= elm.to!T();
		}
		return arr;
	}
}