program main
implicit None
	integer::n,k,p,a,i,j,b
	integer,allocatable::d(:)
	character(len = 5)::c
	
	read *,n,k
	allocate(d(k))
	
	read *,d
	
	do
		p = 0
		write(c,"(i5)")n
		c =adjustl(c)
		a =len_trim(c)
		do i = 1,a
			do j = 1,k
				read(c(i:i),*)b
				if(b == d(j)) p = 1
			enddo
		enddo
		if(p == 1)then
			n = n + 1
			else
			exit
		endif
	enddo
	
	print *,n
	
end program main