program ABC042C
    implicit none
    integer(8)::N,K,i,j,h,ans,hmod
    integer(8)::flg=0
    integer(8),allocatable,dimension(:)::D
    read(5,*)N,K
    allocate(D(K))
    read(5,*)(D(i),i=1,K)
    do i=N,10*N
        flg=0
        h=i
        do
            hmod=mod(h,10)
            do j=1,K
                if(D(j)==hmod)then
                    flg=1
                    exit
                end if
            end do
            h=h/10
            if(h==0)exit
        end do
        if(flg==0)then
            ans=i
            exit
        end if
    end do
    print'(i0)',ans
end program ABC042C