def zeroTrim(s):
    while s[0] == '0':
        if len(s) == 1:
            break
        s = s[1:]
    return s

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

def calc(N, K):
    digit = len(N)
    res = 0

    if K == 1:
        if digit > 1:
            res += (digit - 1) * 9
        res += int(N[0])
    elif K == 2:
        if digit <= 1:
            return 0
        if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
        res += calc(zeroTrim(N[1:]), 1)
    else:
        if digit <= 2:
            return 0
        if digit > 3:
            res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
        
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 2)
        res += calc(zeroTrim(N[1:]), 2)
    return res

print(calc(N, K)) def zeroTrim(s):
    while s[0] == '0':
        if len(s) == 1:
            break
        s = s[1:]
    return s zeroTrim while s[0] == '0':
        if len(s) == 1:
            break
        s = s[1:]
     s[0] == '0' s[0] s 0 '0' if len(s) == 1:
            break
         len(s) == 1 len(s) len s 1 break s = s[1:] s s[1:] s 1: 1 return s s s s N = input() N input() input K = int(input()) K int(input()) int input() input def calc(N, K):
    digit = len(N)
    res = 0

    if K == 1:
        if digit > 1:
            res += (digit - 1) * 9
        res += int(N[0])
    elif K == 2:
        if digit <= 1:
            return 0
        if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
        res += calc(zeroTrim(N[1:]), 1)
    else:
        if digit <= 2:
            return 0
        if digit > 3:
            res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
        
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 2)
        res += calc(zeroTrim(N[1:]), 2)
    return res calc digit = len(N) digit len(N) len N res = 0 res 0 if K == 1:
        if digit > 1:
            res += (digit - 1) * 9
        res += int(N[0])
    elif K == 2:
        if digit <= 1:
            return 0
        if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
        res += calc(zeroTrim(N[1:]), 1)
    else:
        if digit <= 2:
            return 0
        if digit > 3:
            res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
        
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 2)
        res += calc(zeroTrim(N[1:]), 2)
     K == 1 K 1 if digit > 1:
            res += (digit - 1) * 9
         digit > 1 digit 1 res += (digit - 1) * 9 res (digit - 1) * 9 digit - 1 digit 1 9 res += int(N[0]) res int(N[0]) int N[0] N 0 elif K == 2:
        if digit <= 1:
            return 0
        if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
        res += calc(zeroTrim(N[1:]), 1)
     K == 2 K 2 if digit <= 1:
            return 0
         digit <= 1 digit 1 return 0 0 if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
         digit > 2 digit 2 res += 9 * 9 * (digit - 1) * (digit - 2) // 2 res 9 * 9 * (digit - 1) * (digit - 2) // 2 9 * 9 * (digit - 1) * (digit - 2) 9 * 9 * (digit - 1) 9 * 9 9 9 digit - 1 digit 1 digit - 2 digit 2 2 for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
         i range(int(N[0])-1) range int(N[0])-1 int(N[0]) int N[0] N 0 1 res += calc('9'*(digit-1), 1) res calc('9'*(digit-1), 1) calc '9'*(digit-1) '9' digit-1 digit 1 1 res += calc(zeroTrim(N[1:]), 1) res calc(zeroTrim(N[1:]), 1) calc zeroTrim(N[1:]) zeroTrim N[1:] N 1: 1 1 if digit <= 2:
            return 0
         digit <= 2 digit 2 return 0 0 if digit > 3:
            res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
        
         digit > 3 digit 3 res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6 res 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) 9 * 9 * 9 * (digit - 1) * (digit - 2) 9 * 9 * 9 * (digit - 1) 9 * 9 * 9 9 * 9 9 9 9 digit - 1 digit 1 digit - 2 digit 2 digit - 3 digit 3 6 for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 2)
         i range(int(N[0])-1) range int(N[0])-1 int(N[0]) int N[0] N 0 1 res += calc('9'*(digit-1), 2) res calc('9'*(digit-1), 2) calc '9'*(digit-1) '9' digit-1 digit 1 2 res += calc(zeroTrim(N[1:]), 2) res calc(zeroTrim(N[1:]), 2) calc zeroTrim(N[1:]) zeroTrim N[1:] N 1: 1 2 return res res N N K K print(calc(N, K)) print calc(N, K) calc N K N = input() input() N K = int(input()) int(input()) K def zeroTrim(s):
    while s[0] == '0':
        if len(s) == 1:
            break
        s = s[1:]
    return s def zeroTrim(s):
    while s[0] == '0':
        if len(s) == 1:
            break
        s = s[1:]
    return s zeroTrim def calc(N, K):
    digit = len(N)
    res = 0

    if K == 1:
        if digit > 1:
            res += (digit - 1) * 9
        res += int(N[0])
    elif K == 2:
        if digit <= 1:
            return 0
        if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
        res += calc(zeroTrim(N[1:]), 1)
    else:
        if digit <= 2:
            return 0
        if digit > 3:
            res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
        
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 2)
        res += calc(zeroTrim(N[1:]), 2)
    return res def calc(N, K):
    digit = len(N)
    res = 0

    if K == 1:
        if digit > 1:
            res += (digit - 1) * 9
        res += int(N[0])
    elif K == 2:
        if digit <= 1:
            return 0
        if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
        res += calc(zeroTrim(N[1:]), 1)
    else:
        if digit <= 2:
            return 0
        if digit > 3:
            res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
        
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 2)
        res += calc(zeroTrim(N[1:]), 2)
    return res calc
def zeroTrim(s):
    while s[0] == '0':
        if len(s) == 1:
            break
        s = s[1:]
    return s

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

def calc(N, K):
    digit = len(N)
    res = 0

    if K == 1:
        if digit > 1:
            res += (digit - 1) * 9
        res += int(N[0])
    elif K == 2:
        if digit <= 1:
            return 0
        if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
        res += calc(zeroTrim(N[1:]), 1)
    else:
        if digit <= 2:
            return 0
        if digit > 3:
            res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
        
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 2)
        res += calc(zeroTrim(N[1:]), 2)
    return res

print(calc(N, K))