import math
n = int(input())
K = int(input())

def calk1(n):
    if n == 0: return 0
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
if n < 10 ** (K - 1): print(0)
else:
    if K == 1: print(calk1(n))
    elif K == 2: print(calk2(n))
    else: print(calk3(n)) import math math n = int(input()) n int(input()) int input() input K = int(input()) K int(input()) int input() input def calk1(n):
    if n == 0: return 0
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num calk1 if n == 0: return 0
     n == 0 n 0 m = int(math.log10(n)) m int(math.log10(n)) int math.log10(n) math.log10 math log10 n num = m * 9 num m * 9 m 9 num += n//(10**m) num n//(10**m) n 10**m 10 m return num num n n def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num calk2 m = int(math.log10(n)) m int(math.log10(n)) int math.log10(n) math.log10 math log10 n num = m * (m - 1) // 2 * 9**2 num m * (m - 1) // 2 * 9**2 m * (m - 1) // 2 m * (m - 1) m m - 1 m 1 2 9**2 9 2 num += (n//(10**m)-1) * m * 9 num (n//(10**m)-1) * m * 9 (n//(10**m)-1) * m n//(10**m)-1 n//(10**m) n 10**m 10 m 1 m 9 num += calk1(n - (n//(10**m)*10**m)) num calk1(n - (n//(10**m)*10**m)) calk1 n - (n//(10**m)*10**m) n n//(10**m)*10**m n//(10**m) n 10**m 10 m 10**m 10 m return num num n n def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num calk3 m = int(math.log10(n)) m int(math.log10(n)) int math.log10(n) math.log10 math log10 n num = m * (m - 1) * (m - 2) // 6 * 9**3 num m * (m - 1) * (m - 2) // 6 * 9**3 m * (m - 1) * (m - 2) // 6 m * (m - 1) * (m - 2) m * (m - 1) m m - 1 m 1 m - 2 m 2 6 9**3 9 3 num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2) num (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2) n//(10**m)-1 n//(10**m) n 10**m 10 m 1 m * (m - 1) // 2 * 9**2 m * (m - 1) // 2 m * (m - 1) m m - 1 m 1 2 9**2 9 2 num += calk2(n - (n//(10**m)*10**m)) num calk2(n - (n//(10**m)*10**m)) calk2 n - (n//(10**m)*10**m) n n//(10**m)*10**m n//(10**m) n 10**m 10 m 10**m 10 m return num num n n if n < 10 ** (K - 1): print(0)
else:
    if K == 1: print(calk1(n))
    elif K == 2: print(calk2(n))
    else: print(calk3(n)) n < 10 ** (K - 1) n 10 ** (K - 1) 10 K - 1 K 1 if K == 1: print(calk1(n))
    elif K == 2: print(calk2(n))
    else: print(calk3(n)) K == 1 K 1 elif K == 2: print(calk2(n))
     K == 2 K 2 def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num calk3 def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num calk2 n = int(input()) int(input()) n def calk1(n):
    if n == 0: return 0
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num def calk1(n):
    if n == 0: return 0
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num calk1 K = int(input()) int(input()) K
import math
n = int(input())
K = int(input())

def calk1(n):
    if n == 0: return 0
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
if n < 10 ** (K - 1): print(0)
else:
    if K == 1: print(calk1(n))
    elif K == 2: print(calk2(n))
    else: print(calk3(n))
