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


def run():
    dp = [[[0] * 4 for _ in range(2)] for _ in range(len(sN) + 1)]
    dp[0][0][0] = 1

    for i in range(len(sN)):
        for j in range(2):
            # j=0 : 現在の桁まで数字が同じ
            # j=1 : すでに小さい数値とわかっている

            # limには次の桁の数字の最大値を代入する
            lim = 9 if j == 1 else (ord(sN[i]) - ord('0'))
            for k in range(lim + 1):
                for l in range(4):
                    nl = l + int(k > 0)
                    if nl >= 4: continue
                    dp[i + 1][k < lim or j == 1][nl] += dp[i][j][l]

        # print(dp)

    print(dp[len(sN)][0][K] + dp[len(sN)][1][K])


if __name__ == '__main__':
    run() sN = input() sN input() input K = int(input()) K int(input()) int input() input N = int(sN) N int(sN) int sN def run():
    dp = [[[0] * 4 for _ in range(2)] for _ in range(len(sN) + 1)]
    dp[0][0][0] = 1

    for i in range(len(sN)):
        for j in range(2):
            # j=0 : 現在の桁まで数字が同じ
            # j=1 : すでに小さい数値とわかっている

            # limには次の桁の数字の最大値を代入する
            lim = 9 if j == 1 else (ord(sN[i]) - ord('0'))
            for k in range(lim + 1):
                for l in range(4):
                    nl = l + int(k > 0)
                    if nl >= 4: continue
                    dp[i + 1][k < lim or j == 1][nl] += dp[i][j][l]

        # print(dp)

    print(dp[len(sN)][0][K] + dp[len(sN)][1][K]) run [[0] * 4 for _ in range(2)] for _ in range(len(sN) + 1) for _ in range(len(sN) + 1) _ range(len(sN) + 1) range len(sN) + 1 len(sN) len sN 1 for _ in range(len(sN) + 1) [[0] * 4 for _ in range(2)] dp = [[[0] * 4 for _ in range(2)] for _ in range(len(sN) + 1)] dp [[[0] * 4 for _ in range(2)] for _ in range(len(sN) + 1)] dp[0][0][0] = 1 dp[0][0][0] [0] [0] dp 0 0 0 1 for i in range(len(sN)):
        for j in range(2):
            # j=0 : 現在の桁まで数字が同じ
            # j=1 : すでに小さい数値とわかっている

            # limには次の桁の数字の最大値を代入する
            lim = 9 if j == 1 else (ord(sN[i]) - ord('0'))
            for k in range(lim + 1):
                for l in range(4):
                    nl = l + int(k > 0)
                    if nl >= 4: continue
                    dp[i + 1][k < lim or j == 1][nl] += dp[i][j][l]

        # print(dp)

     i range(len(sN)) range len(sN) len sN for j in range(2):
            # j=0 : 現在の桁まで数字が同じ
            # j=1 : すでに小さい数値とわかっている

            # limには次の桁の数字の最大値を代入する
            lim = 9 if j == 1 else (ord(sN[i]) - ord('0'))
            for k in range(lim + 1):
                for l in range(4):
                    nl = l + int(k > 0)
                    if nl >= 4: continue
                    dp[i + 1][k < lim or j == 1][nl] += dp[i][j][l]

        # print(dp)

     j range(2) range 2 lim = 9 if j == 1 else (ord(sN[i]) - ord('0')) lim 9 if j == 1 else (ord(sN[i]) - ord('0')) j == 1 j 1 9 ord(sN[i]) - ord('0') ord(sN[i]) ord sN[i] sN i ord('0') ord '0' for k in range(lim + 1):
                for l in range(4):
                    nl = l + int(k > 0)
                    if nl >= 4: continue
                    dp[i + 1][k < lim or j == 1][nl] += dp[i][j][l]

        # print(dp)

     k range(lim + 1) range lim + 1 lim 1 for l in range(4):
                    nl = l + int(k > 0)
                    if nl >= 4: continue
                    dp[i + 1][k < lim or j == 1][nl] += dp[i][j][l]

        # print(dp)

     l range(4) range 4 nl = l + int(k > 0) nl l + int(k > 0) l int(k > 0) int k > 0 k 0 if nl >= 4: continue
                     nl >= 4 nl 4 dp[i + 1][k < lim or j == 1][nl] += dp[i][j][l] dp[i + 1][k < lim or j == 1][nl] [k < lim or j == 1] [i + 1] dp i + 1 i 1 k < lim or j == 1 k < lim k lim j == 1 j 1 nl dp[i][j][l] [j] [i] dp i j l print(dp[len(sN)][0][K] + dp[len(sN)][1][K]) print dp[len(sN)][0][K] + dp[len(sN)][1][K] dp[len(sN)][0][K] [0] [len(sN)] dp len(sN) len sN 0 K dp[len(sN)][1][K] [1] [len(sN)] dp len(sN) len sN 1 K if __name__ == '__main__':
    run() __name__ == '__main__' __name__ '__main__' run() run N = int(sN) int(sN) N def run():
    dp = [[[0] * 4 for _ in range(2)] for _ in range(len(sN) + 1)]
    dp[0][0][0] = 1

    for i in range(len(sN)):
        for j in range(2):
            # j=0 : 現在の桁まで数字が同じ
            # j=1 : すでに小さい数値とわかっている

            # limには次の桁の数字の最大値を代入する
            lim = 9 if j == 1 else (ord(sN[i]) - ord('0'))
            for k in range(lim + 1):
                for l in range(4):
                    nl = l + int(k > 0)
                    if nl >= 4: continue
                    dp[i + 1][k < lim or j == 1][nl] += dp[i][j][l]

        # print(dp)

    print(dp[len(sN)][0][K] + dp[len(sN)][1][K]) def run():
    dp = [[[0] * 4 for _ in range(2)] for _ in range(len(sN) + 1)]
    dp[0][0][0] = 1

    for i in range(len(sN)):
        for j in range(2):
            # j=0 : 現在の桁まで数字が同じ
            # j=1 : すでに小さい数値とわかっている

            # limには次の桁の数字の最大値を代入する
            lim = 9 if j == 1 else (ord(sN[i]) - ord('0'))
            for k in range(lim + 1):
                for l in range(4):
                    nl = l + int(k > 0)
                    if nl >= 4: continue
                    dp[i + 1][k < lim or j == 1][nl] += dp[i][j][l]

        # print(dp)

    print(dp[len(sN)][0][K] + dp[len(sN)][1][K]) run sN = input() input() sN K = int(input()) int(input()) K
sN = input()
K = int(input())
N = int(sN)


def run():
    dp = [[[0] * 4 for _ in range(2)] for _ in range(len(sN) + 1)]
    dp[0][0][0] = 1

    for i in range(len(sN)):
        for j in range(2):
            # j=0 : 現在の桁まで数字が同じ
            # j=1 : すでに小さい数値とわかっている

            # limには次の桁の数字の最大値を代入する
            lim = 9 if j == 1 else (ord(sN[i]) - ord('0'))
            for k in range(lim + 1):
                for l in range(4):
                    nl = l + int(k > 0)
                    if nl >= 4: continue
                    dp[i + 1][k < lim or j == 1][nl] += dp[i][j][l]

        # print(dp)

    print(dp[len(sN)][0][K] + dp[len(sN)][1][K])


if __name__ == '__main__':
    run()
