import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n = input()
    k = int(input())

    num = int(n)

    if k == 1:
        ans = (len(n)-1) * 9
        ans += int(n[0])
        print(ans)
        return

    elif k == 2:
        if num < 100:
            print(num-10-(int(n[0])-1))
            return
        else:
            ans = 0
            ans = int(n[1])+9*(len(n)-2)
            ans += (int(n[0])-1) * 9 * (len(n)-1)
            ans += 9*9 * combinations_count(len(n)-1, 2)
            print(ans)
            return

    elif k == 3:
        if num < 111:
            print(0)
            return
        elif num < 1000:
            ans = (int(n[0])-1) * 81
            ans += (int(n[1])-1) * 9
            if n[1]>0:
                ans += (int(n[2]))
            print(ans)
            return
        else:
            n_len = len(n)
            ans = 9*9*9 * combinations_count(n_len-1, 3) # 一桁めが０
            ans += (int(n[1])-1) * (9*(n_len-2)) + int(n[2])+(9*(n_len-3)) # 一桁めがmax & 二桁めが1-9
            ans += (9*9) * combinations_count(n_len-2, 2) # 一桁めがmax & 二桁めが0
            ans += (int(n[0])-1) * (9*9)*combinations_count(n_len-1, 2) # 一桁めが1-<max
            print(ans)
            return


if __name__ == '__main__':
    main()
