def resolve():
    s = input()
    N = int(s)
    K = int(input())
    ans = 0
    d = len(s)
    if d < K:
        print(ans)
        return
    for i in range(1, d):
        if i < K:
            continue
        else:
            if i == 1 and K == 1:
                ans += 9
            elif i == 2 and K == 2:
                ans += 9*9
            elif i == 3 and K == 3:
                ans += 9*9*9
            else:
                if K == 1:
                    ans += 9
                elif K == 2:
                    ans += 9*9*(i-1)
                else:
                    ans += 9*9*9*(i-1)*(i-2)//2
    # print(ans)
    if K == 1:
        ans += int(s[0])
    elif K == 2:
        ans += int(s[1])
        if int(s[0]) > 1:
            ans += (int(s[0])-1)*9
        if d > K:
            ans += int(s[0])*(d-2)*9
    else:
        ans += int(s[2])
        if int(s[1]) > 1:
            ans += (int(s[1])-1)*9
            if int(s[0]) > 1:
                ans += (int(s[0])-1)*9*9
        if d > K:
            ans += int(s[0])*int(s[1])*(d-3)*9*2
            if d > K+1:
                ans += int(s[0])*9*9*(d-3)*(d-4)//2
    print(ans)
resolve()