import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    N = input()
    K = int(input())
    L = len(N)
    ans = 0
    if int(N) < 1000:
        for k in range(1,int(N)+1):
            if str(k).count("0") + K == len(str(k)):
                ans += 1
    else:
        if K == 1:
            ans = int(N[0])+9*(L-1)
        elif K == 2:
            ans = (int(N[0])-1)*9*(L-1)
            ans += 9*9*((L-1)*(L-2)//2)
            ans += 9*(L-2) + int(N[1])
        else:
            ans = (int(N[0])-1)*9*9*((L-1)*(L-2)//2)
            ans += 9*9*9*((L-1)*(L-2)*(L-3)//6)
#            ans += (int(N[1])-1)*9*(L-2)
            ans += 9*9*((L-1)*(L-2)//2)
    print(ans)

if __name__ == '__main__':
    main()
