import sys
import math

def combinations(n, r):
    if n < 0 or n < r:
        return 0
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

def main():
    n = input().rstrip()
    k = int(input())
    if k == 1:
        print((int(n[0]) - 1) + 9 * (len(n) -  1) + 1)
    elif k == 2:
        a = (int(n[0]) - 1) * 9 * (len(n) - 1) + int(combinations(len(n) - 1, 2) * 9*9)
        b = int(n[1]) + 9 * (len(n)-2)
        print(a + b)
    elif k == 3:
        a = (int(n[1]) - 1) * 9 * (len(n) - 2) + int(combinations(len(n)-2, 2) * 9*9) + (int(n[2]) + 9*(len(n) - 3))
        b = (int(n[0]) - 1) * int(combinations(len(n)-1, 2) * 9*9)
        c = int(combinations(len(n)-1, 3) * 9*9*9)
        print(a+b+c)

if __name__ == '__main__':
    main()