import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = input()
    k = int(input())

    # 桁DP
    def digit_DP(S, K):
        L = len(S)
        # dp[決定した桁数][未満フラグ][０以外の数字を使った個数]
        dp = [[[0 for _ in range(4)] for _ in range(2)] for _ in range(101)]
        dp[0][0][0] = 1
        for i in range(L):  # 今見ている桁
            D = int(S[i])
            for j in range(2):  # 未満フラグ(0 or 1)
                for k in range(4):  # ０以外の数字を使った個数が0~3
                    for d in range(10 if j else D + 1):
                        cnt = k
                        if d != 0:
                            cnt += 1
                        if cnt > K:
                            continue
                        dp[i + 1][j or (d < D)][cnt] += dp[i][j][k]

        return dp[L][0][K] + dp[L][1][K]

    print(digit_DP(n, k))


if __name__ == '__main__':
    resolve() import sys sys sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 f_inf = float('inf') f_inf float('inf') float 'inf' mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 def resolve():
    n = input()
    k = int(input())

    # 桁DP
    def digit_DP(S, K):
        L = len(S)
        # dp[決定した桁数][未満フラグ][０以外の数字を使った個数]
        dp = [[[0 for _ in range(4)] for _ in range(2)] for _ in range(101)]
        dp[0][0][0] = 1
        for i in range(L):  # 今見ている桁
            D = int(S[i])
            for j in range(2):  # 未満フラグ(0 or 1)
                for k in range(4):  # ０以外の数字を使った個数が0~3
                    for d in range(10 if j else D + 1):
                        cnt = k
                        if d != 0:
                            cnt += 1
                        if cnt > K:
                            continue
                        dp[i + 1][j or (d < D)][cnt] += dp[i][j][k]

        return dp[L][0][K] + dp[L][1][K]

    print(digit_DP(n, k)) resolve n = input() n input() input k = int(input()) k int(input()) int input() input def digit_DP(S, K):
        L = len(S)
        # dp[決定した桁数][未満フラグ][０以外の数字を使った個数]
        dp = [[[0 for _ in range(4)] for _ in range(2)] for _ in range(101)]
        dp[0][0][0] = 1
        for i in range(L):  # 今見ている桁
            D = int(S[i])
            for j in range(2):  # 未満フラグ(0 or 1)
                for k in range(4):  # ０以外の数字を使った個数が0~3
                    for d in range(10 if j else D + 1):
                        cnt = k
                        if d != 0:
                            cnt += 1
                        if cnt > K:
                            continue
                        dp[i + 1][j or (d < D)][cnt] += dp[i][j][k]

        return dp[L][0][K] + dp[L][1][K]

     digit_DP L = len(S) L len(S) len S [[0 for _ in range(4)] for _ in range(2)] for _ in range(101) for _ in range(101) _ range(101) range 101 for _ in range(101) [[0 for _ in range(4)] for _ in range(2)] dp = [[[0 for _ in range(4)] for _ in range(2)] for _ in range(101)] dp [[[0 for _ in range(4)] for _ in range(2)] for _ in range(101)] dp[0][0][0] = 1 dp[0][0][0] [0] [0] dp 0 0 0 1 for i in range(L):  # 今見ている桁
            D = int(S[i])
            for j in range(2):  # 未満フラグ(0 or 1)
                for k in range(4):  # ０以外の数字を使った個数が0~3
                    for d in range(10 if j else D + 1):
                        cnt = k
                        if d != 0:
                            cnt += 1
                        if cnt > K:
                            continue
                        dp[i + 1][j or (d < D)][cnt] += dp[i][j][k]

         i range(L) range L D = int(S[i]) D int(S[i]) int S[i] S i for j in range(2):  # 未満フラグ(0 or 1)
                for k in range(4):  # ０以外の数字を使った個数が0~3
                    for d in range(10 if j else D + 1):
                        cnt = k
                        if d != 0:
                            cnt += 1
                        if cnt > K:
                            continue
                        dp[i + 1][j or (d < D)][cnt] += dp[i][j][k]

         j range(2) range 2 for k in range(4):  # ０以外の数字を使った個数が0~3
                    for d in range(10 if j else D + 1):
                        cnt = k
                        if d != 0:
                            cnt += 1
                        if cnt > K:
                            continue
                        dp[i + 1][j or (d < D)][cnt] += dp[i][j][k]

         k range(4) range 4 for d in range(10 if j else D + 1):
                        cnt = k
                        if d != 0:
                            cnt += 1
                        if cnt > K:
                            continue
                        dp[i + 1][j or (d < D)][cnt] += dp[i][j][k]

         d range(10 if j else D + 1) range 10 if j else D + 1 j 10 D + 1 D 1 cnt = k cnt k if d != 0:
                            cnt += 1
                         d != 0 d 0 cnt += 1 cnt 1 if cnt > K:
                            continue
                         cnt > K cnt K continue dp[i + 1][j or (d < D)][cnt] += dp[i][j][k] dp[i + 1][j or (d < D)][cnt] [j or (d < D)] [i + 1] dp i + 1 i 1 j or (d < D) j d < D d D cnt dp[i][j][k] [j] [i] dp i j k return dp[L][0][K] + dp[L][1][K] dp[L][0][K] + dp[L][1][K] dp[L][0][K] [0] [L] dp L 0 K dp[L][1][K] [1] [L] dp L 1 K S S K K print(digit_DP(n, k)) print digit_DP(n, k) digit_DP n k if __name__ == '__main__':
    resolve() __name__ == '__main__' __name__ '__main__' resolve() resolve f_inf = float('inf') float('inf') f_inf def resolve():
    n = input()
    k = int(input())

    # 桁DP
    def digit_DP(S, K):
        L = len(S)
        # dp[決定した桁数][未満フラグ][０以外の数字を使った個数]
        dp = [[[0 for _ in range(4)] for _ in range(2)] for _ in range(101)]
        dp[0][0][0] = 1
        for i in range(L):  # 今見ている桁
            D = int(S[i])
            for j in range(2):  # 未満フラグ(0 or 1)
                for k in range(4):  # ０以外の数字を使った個数が0~3
                    for d in range(10 if j else D + 1):
                        cnt = k
                        if d != 0:
                            cnt += 1
                        if cnt > K:
                            continue
                        dp[i + 1][j or (d < D)][cnt] += dp[i][j][k]

        return dp[L][0][K] + dp[L][1][K]

    print(digit_DP(n, k)) def resolve():
    n = input()
    k = int(input())

    # 桁DP
    def digit_DP(S, K):
        L = len(S)
        # dp[決定した桁数][未満フラグ][０以外の数字を使った個数]
        dp = [[[0 for _ in range(4)] for _ in range(2)] for _ in range(101)]
        dp[0][0][0] = 1
        for i in range(L):  # 今見ている桁
            D = int(S[i])
            for j in range(2):  # 未満フラグ(0 or 1)
                for k in range(4):  # ０以外の数字を使った個数が0~3
                    for d in range(10 if j else D + 1):
                        cnt = k
                        if d != 0:
                            cnt += 1
                        if cnt > K:
                            continue
                        dp[i + 1][j or (d < D)][cnt] += dp[i][j][k]

        return dp[L][0][K] + dp[L][1][K]

    print(digit_DP(n, k)) resolve mod = 10 ** 9 + 7 10 ** 9 + 7 mod
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = input()
    k = int(input())

    # 桁DP
    def digit_DP(S, K):
        L = len(S)
        # dp[決定した桁数][未満フラグ][０以外の数字を使った個数]
        dp = [[[0 for _ in range(4)] for _ in range(2)] for _ in range(101)]
        dp[0][0][0] = 1
        for i in range(L):  # 今見ている桁
            D = int(S[i])
            for j in range(2):  # 未満フラグ(0 or 1)
                for k in range(4):  # ０以外の数字を使った個数が0~3
                    for d in range(10 if j else D + 1):
                        cnt = k
                        if d != 0:
                            cnt += 1
                        if cnt > K:
                            continue
                        dp[i + 1][j or (d < D)][cnt] += dp[i][j][k]

        return dp[L][0][K] + dp[L][1][K]

    print(digit_DP(n, k))


if __name__ == '__main__':
    resolve()
