program abc042_a
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: k,i,n,t
    integer(int32),allocatable:: d(:)
    logical:: hate, hnum(0:9)


    read*, n,k
    allocate(d(k))
    read*, d(:)

    hnum(:) = .false.
    do i=1,k
        hnum(d(i)) = .true.
    end do

    do
        hate = .false.
        do i=0,int(log10(dble(n)))
            t = mod(n/(10**i),10)
            if (hnum(t)) hate=.true.
        end do
        if (hate) then
            n=n+1
        else
            print'(i0)', n
            stop
        end if
    end do
end program abc042_a