PROGRAM ATCODER

implicit none
integer :: n, k, cost, i, j, check
integer,allocatable :: d(:)

read(*,*) n, k
allocate (d(k))
read(*,*) (d(i), i=1,k)


cost = n - 1
do
	check = 0
    cost = cost + 1
	do j = 1, k
        if(mod(cost,10) == d(j))then
	        check = 1
		end if
        if(mod(cost,100)/10 == d(j) .and. cost >= 10)then
	        check = 1
		end if
		if(mod(cost,1000)/100 == d(j) .and. cost >= 100)then
            check = 1
		end if
		if(cost/1000 == d(j) .and. cost >= 1000)then
            check = 1
		end if
	end do
    if (check == 0) then
		write(*,'(i0)') cost
		stop
	end if
end do

END PROGRAM ATCODER