N = int(input())
K = int(input())
ans = 0
if K == 1:
    ans +=  9 * (len(str(N))-1)
elif K == 2:
    for i in range(2,len(str(N))):
        print(i)
        ans += 9*9*(i-1)
else:
    n = len(str(N))
    for i in range(3,len(str(N))):
        for j in range(1,i-1):
            for k in range(2,i):
                ans += 9*9*9
print(ans)
if K == 1:
    ans += int(str(N)[0])
elif K == 2:
    val = int(str(N)[0])
    for i in range(1,len(str(N))):
        if i == 1:
            ans -= 9-int(str(N)[1])
        ans += val*9
else:
    for i in range(1,int(str(N)[0])):
        for j in range(1,len(str(N))-1):
            for k in range(j+1,len(str(N))):
                if j == 1:
                    if k == 2:
                        ans += int(str(N)[j]) * int(str(N)[k])
                    else:
                        ans += 9*int(str(N)[j])
                else:
                    ans += 81
print(ans)
