#from fractions import gcd
#mod = 10 ** 9 + 7
#N = int(input())
#a = list(map(int,input().split()))
#a,b,c = map(int,input().split())
#ans = [0] * N
#math.ceilで切り上げ
#dp = [[0] * 4 for i in range(3)] #2次元配列初期化
#dp = [[[0] * 2 for i in range(3)] for j in range(5)]

import math
import string

def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

def splitintinput():
    return map(int,input().split())

N = str(intinput())
K = intinput()
s = len(str(N))
flag = 0
dp = [[[0] * 3 for i in range(5)] for j in range(150)]
dp[0][0][0] = 1
dp[1][1][1] += int(N[0])-1
dp[2][2][1] += int(N[1])-1
dp[3][3][1] += int(N[2])-1
for h in range(1,s+1):
    dp[h][0][0] = 0
    dp[h][0][1] = 1
    for i in range(1,4):
        dp[h][i][0] += dp[h-1][i-1][0]
        dp[h][i][1] +=  dp[h-1][i-1][1] * 9 + dp[h-1][i][0] + dp[h-1][i][1]

print(dp[s][K][0]+dp[s][K][1])
            
                
                
 

