N = input()
K = int(input())

ans = 0
if K == 1:
    for i in range(1,len(N)+1):
        if i != len(N):
            ans += 9
        else:
            ans += (int(N) // (10 ** (i-1)))
elif K == 2:
    for i in range(2, len(N)+1):
        if i != len(N):
            ans += 9 * 9 * (i-1)
        else:
            s = 0
            n = int(N) // (10 ** (i-1))
            ans += (n-1) * 9 * (i-1)
            for j in range(1,len(N)):
                if s == 0 and int(N[j]) == 0:
                    continue
                elif s == 1:
                    ans += 9
                else:
                    ans += int(N[j])
                    s = 1
elif K == 3:
    for i in range(3, len(N)+1):
        if i != len(N):
            ans += 9 * 9 * (i-1)
        else:
            s = 0
            n = int(N) // (10 ** (i-1))
            ans += (n-1) * 9 * 9 * (((i-1) * (i-2)) // 2)
            for j in range(1,len(N)):
                if s == 0 and int(N[j]) == 0:
                    continue
                elif s == 1:
                    ans += 9 * 9 * (((len(N)-j) * (max(len(N)-j-1, 0))) // 2)
                    break
                else:
                    ans += (int(N[j])-1) * 9 * (len(N)-j-1)
                    for k in range(j+1,len(N)):
                        if s == 0 and int(N[k]) == 0:
                            continue
                        elif s == 1:
                            ans += 9
                        else:
                            ans += int(N[k])
                            s = 1
print(ans)
                            
                            
                            
                    
        
                
            
    
        