n=int(input())
lenn=len(str(n))

k=int(input())
#k:1~3

result=0

if n <=9:
    if k==1:
        print(n)
    else:
        print(0)
    exit()
elif n <=99:
    if k==1:
        print(n//10+9)
    elif k==2:
        print((n//10-1)*9+n%10)
    else:
        print(0)
    exit()
    """
elif n <=999:
    if k==1:
        print(n//100+9+9)
    elif k==2:
        print((n//100-1)*9+9*9)
    else:
        print(0)
    exit()
    """
else:
    if k==1:
        print(9*(lenn-1)+n//(10**(lenn-1)))
    elif k==2:
        result=0
        #先頭の文字を抜いた状態で
        result+=9*9*(lenn-1)*(lenn-2)//1//2
        #print(result)
        #先頭の文字を1ひいて
        result+=(n//(10**(lenn-1))-1)*9*(lenn-1)
        #print(result)

        for i in str(n)[1:]:
            result+=int(i)
        print(result)
    else:
        if lenn==3:
            result=(n//(10**(lenn-1))-1)*9*9
            temp=1
            for i in str(n)[1:]:
                temp=temp*int(i)
            result+=temp
            print(result)
            exit()
        else:
            result=0
            #先頭の文字を抜いた状態で
            result+=9*9*9*(lenn-1)*(lenn-2)*(lenn-3)//1//2//3
        #先頭の文字を1ひいて
            result+=(n//(10**(lenn-1))-1)*9*9*(lenn-1)*(lenn-2)//1//2
            temp=1
            i=1
            while i<lenn:
                j=i+1
                while j<lenn:
                    result+=int(str(n)[i])*int(str(n)[j])
                    j+=1
                i+=1

            print(result+17)





