import sys

input = sys.stdin.readline


def solve_K_1(N):
    S = str(N)
    d = len(S)
    return 9 * (d - 1) + int(S[0])


def solve_K_2(N):
    if N <= 99:
        return N - solve_K_1(N)
    S = str(N)
    d = len(S)
    res = 0
    res += 81 * (d - 1) * (d - 2) // 2
    res += 9 * (d - 1) * (int(S[0]) - 1)
    x = 0
    for i in range(1, d):
        if S[i] != "0":
            x = int(S[i])
            break
    i += 1
    res += x + 9 * (d - i)
    return res


def solve_K_3(N):
    if N <= 999:
        return N - solve_K_1(N) - solve_K_2(N)
    S = str(N)
    d = len(S)
    res = 0
    for n in range(3, d):
        res += 729 * (n - 1) * (n - 2) // 2
    res += 81 * (d - 1) * (d - 2) // 2 * (int(S[0]) - 1)
    res += solve_K_2(int(S[1:]))
    return res


def main():
    N = int(input())
    K = int(input())

    if K == 1:
        ans = solve_K_1(N)
    elif K == 2:
        ans = solve_K_2(N)
    elif K == 3:
        ans = solve_K_3(N)

    print(ans)


if __name__ == "__main__":
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def solve_K_1(N):
    S = str(N)
    d = len(S)
    return 9 * (d - 1) + int(S[0]) solve_K_1 S = str(N) S str(N) str N d = len(S) d len(S) len S return 9 * (d - 1) + int(S[0]) 9 * (d - 1) + int(S[0]) 9 * (d - 1) 9 d - 1 d 1 int(S[0]) int S[0] S 0 N N def solve_K_2(N):
    if N <= 99:
        return N - solve_K_1(N)
    S = str(N)
    d = len(S)
    res = 0
    res += 81 * (d - 1) * (d - 2) // 2
    res += 9 * (d - 1) * (int(S[0]) - 1)
    x = 0
    for i in range(1, d):
        if S[i] != "0":
            x = int(S[i])
            break
    i += 1
    res += x + 9 * (d - i)
    return res solve_K_2 if N <= 99:
        return N - solve_K_1(N)
     N <= 99 N 99 return N - solve_K_1(N) N - solve_K_1(N) N solve_K_1(N) solve_K_1 N S = str(N) S str(N) str N d = len(S) d len(S) len S res = 0 res 0 res += 81 * (d - 1) * (d - 2) // 2 res 81 * (d - 1) * (d - 2) // 2 81 * (d - 1) * (d - 2) 81 * (d - 1) 81 d - 1 d 1 d - 2 d 2 2 res += 9 * (d - 1) * (int(S[0]) - 1) res 9 * (d - 1) * (int(S[0]) - 1) 9 * (d - 1) 9 d - 1 d 1 int(S[0]) - 1 int(S[0]) int S[0] S 0 1 x = 0 x 0 for i in range(1, d):
        if S[i] != "0":
            x = int(S[i])
            break
     i range(1, d) range 1 d if S[i] != "0":
            x = int(S[i])
            break
     S[i] != "0" S[i] S i "0" x = int(S[i]) x int(S[i]) int S[i] S i break i += 1 i 1 res += x + 9 * (d - i) res x + 9 * (d - i) x 9 * (d - i) 9 d - i d i return res res N N def solve_K_3(N):
    if N <= 999:
        return N - solve_K_1(N) - solve_K_2(N)
    S = str(N)
    d = len(S)
    res = 0
    for n in range(3, d):
        res += 729 * (n - 1) * (n - 2) // 2
    res += 81 * (d - 1) * (d - 2) // 2 * (int(S[0]) - 1)
    res += solve_K_2(int(S[1:]))
    return res solve_K_3 if N <= 999:
        return N - solve_K_1(N) - solve_K_2(N)
     N <= 999 N 999 return N - solve_K_1(N) - solve_K_2(N) N - solve_K_1(N) - solve_K_2(N) N - solve_K_1(N) N solve_K_1(N) solve_K_1 N solve_K_2(N) solve_K_2 N S = str(N) S str(N) str N d = len(S) d len(S) len S res = 0 res 0 for n in range(3, d):
        res += 729 * (n - 1) * (n - 2) // 2
     n range(3, d) range 3 d res += 729 * (n - 1) * (n - 2) // 2 res 729 * (n - 1) * (n - 2) // 2 729 * (n - 1) * (n - 2) 729 * (n - 1) 729 n - 1 n 1 n - 2 n 2 2 res += 81 * (d - 1) * (d - 2) // 2 * (int(S[0]) - 1) res 81 * (d - 1) * (d - 2) // 2 * (int(S[0]) - 1) 81 * (d - 1) * (d - 2) // 2 81 * (d - 1) * (d - 2) 81 * (d - 1) 81 d - 1 d 1 d - 2 d 2 2 int(S[0]) - 1 int(S[0]) int S[0] S 0 1 res += solve_K_2(int(S[1:])) res solve_K_2(int(S[1:])) solve_K_2 int(S[1:]) int S[1:] S 1: 1 return res res N N def main():
    N = int(input())
    K = int(input())

    if K == 1:
        ans = solve_K_1(N)
    elif K == 2:
        ans = solve_K_2(N)
    elif K == 3:
        ans = solve_K_3(N)

    print(ans) main N = int(input()) N int(input()) int input() input K = int(input()) K int(input()) int input() input if K == 1:
        ans = solve_K_1(N)
    elif K == 2:
        ans = solve_K_2(N)
    elif K == 3:
        ans = solve_K_3(N)

     K == 1 K 1 ans = solve_K_1(N) ans solve_K_1(N) solve_K_1 N elif K == 2:
        ans = solve_K_2(N)
     K == 2 K 2 ans = solve_K_2(N) ans solve_K_2(N) solve_K_2 N elif K == 3:
        ans = solve_K_3(N)

     K == 3 K 3 ans = solve_K_3(N) ans solve_K_3(N) solve_K_3 N print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main input = sys.stdin.readline sys.stdin.readline input def solve_K_2(N):
    if N <= 99:
        return N - solve_K_1(N)
    S = str(N)
    d = len(S)
    res = 0
    res += 81 * (d - 1) * (d - 2) // 2
    res += 9 * (d - 1) * (int(S[0]) - 1)
    x = 0
    for i in range(1, d):
        if S[i] != "0":
            x = int(S[i])
            break
    i += 1
    res += x + 9 * (d - i)
    return res def solve_K_2(N):
    if N <= 99:
        return N - solve_K_1(N)
    S = str(N)
    d = len(S)
    res = 0
    res += 81 * (d - 1) * (d - 2) // 2
    res += 9 * (d - 1) * (int(S[0]) - 1)
    x = 0
    for i in range(1, d):
        if S[i] != "0":
            x = int(S[i])
            break
    i += 1
    res += x + 9 * (d - i)
    return res solve_K_2 def main():
    N = int(input())
    K = int(input())

    if K == 1:
        ans = solve_K_1(N)
    elif K == 2:
        ans = solve_K_2(N)
    elif K == 3:
        ans = solve_K_3(N)

    print(ans) def main():
    N = int(input())
    K = int(input())

    if K == 1:
        ans = solve_K_1(N)
    elif K == 2:
        ans = solve_K_2(N)
    elif K == 3:
        ans = solve_K_3(N)

    print(ans) main def solve_K_1(N):
    S = str(N)
    d = len(S)
    return 9 * (d - 1) + int(S[0]) def solve_K_1(N):
    S = str(N)
    d = len(S)
    return 9 * (d - 1) + int(S[0]) solve_K_1 def solve_K_3(N):
    if N <= 999:
        return N - solve_K_1(N) - solve_K_2(N)
    S = str(N)
    d = len(S)
    res = 0
    for n in range(3, d):
        res += 729 * (n - 1) * (n - 2) // 2
    res += 81 * (d - 1) * (d - 2) // 2 * (int(S[0]) - 1)
    res += solve_K_2(int(S[1:]))
    return res def solve_K_3(N):
    if N <= 999:
        return N - solve_K_1(N) - solve_K_2(N)
    S = str(N)
    d = len(S)
    res = 0
    for n in range(3, d):
        res += 729 * (n - 1) * (n - 2) // 2
    res += 81 * (d - 1) * (d - 2) // 2 * (int(S[0]) - 1)
    res += solve_K_2(int(S[1:]))
    return res solve_K_3
import sys

input = sys.stdin.readline


def solve_K_1(N):
    S = str(N)
    d = len(S)
    return 9 * (d - 1) + int(S[0])


def solve_K_2(N):
    if N <= 99:
        return N - solve_K_1(N)
    S = str(N)
    d = len(S)
    res = 0
    res += 81 * (d - 1) * (d - 2) // 2
    res += 9 * (d - 1) * (int(S[0]) - 1)
    x = 0
    for i in range(1, d):
        if S[i] != "0":
            x = int(S[i])
            break
    i += 1
    res += x + 9 * (d - i)
    return res


def solve_K_3(N):
    if N <= 999:
        return N - solve_K_1(N) - solve_K_2(N)
    S = str(N)
    d = len(S)
    res = 0
    for n in range(3, d):
        res += 729 * (n - 1) * (n - 2) // 2
    res += 81 * (d - 1) * (d - 2) // 2 * (int(S[0]) - 1)
    res += solve_K_2(int(S[1:]))
    return res


def main():
    N = int(input())
    K = int(input())

    if K == 1:
        ans = solve_K_1(N)
    elif K == 2:
        ans = solve_K_2(N)
    elif K == 3:
        ans = solve_K_3(N)

    print(ans)


if __name__ == "__main__":
    main()
