program main
    implicit none
    character(101):: s
    integer(8):: dp(0:1,0:3,0:105)=0, k, n
    integer(4):: i1, i2, i3, d, i
    integer(4):: nd, ni1,ni2,ni3, ans=0

    read*, s
    read*, k
    n = len_trim(s)
    dp(0,0,0) = 1


    do i1=0, n-1
        do i2=0, 3
            do i3=0, 1
                read(s(i1+1:i1+1),*) nd
                do d=0,9
                    ni1 = i1+1; ni2 = i2; ni3 = i3 
                    if (d /= 0) ni2=ni2+1
                    if (ni2 > k) cycle
                    if (i3==0) then
                        if (d > nd) cycle
                        if (d < nd) ni3=1
                    end if
                    dp(ni3,ni2,ni1) = dp(ni3,ni2,ni1) + dp(i3,i2,i1)
                end do
            end do
        end do
    end do
    do i=0,n
        print*,'--'
        print*, dp(0,:,i)
        print*, dp(1,:,i)
    end do
    ans = dp(0,k,n)+dp(1,k,n)

    print*, ans
end program main