N = int(input())
K = int(input())

if K ==1:
    sN = str(N)
    keta = len(sN)
    ans = int(sN[0])+9*(keta-1)
    print(ans)
elif K == 2:
    if N < 11:
        print(0)
    else:
        sN = str(N)
        keta = len(sN)
        goukei = 0
        for i in range(keta):
            goukei += (i*9)*9
        if keta > 2:
            ssN = str(N - (N%10))
        else:
            ssN = sN
        
        goukei += int(ssN[0])*9*keta
        for s in sN:
            goukei += int(s)
        print(goukei)
else:
    print(0)