def resolve():
    N = list(input())
    lenN = len(N)
    K = int(input())
    dp = [[[None, None] for _ in range(K+1)] for __ in range(lenN)]

    def rec(i, k, smaller):
        if k==0:
            return 1
        if i>=lenN:
            return 0
        
        if dp[i][k][int(smaller)] is not None:
            return dp[i][k][int(smaller)]
        
        ret = 0
        if smaller:
            ret += rec(i+1, k, True)
            ret += rec(i+1, k-1, True) * 9
        else:
            if N[i] == "0":
                ret += rec(i+1, k, False)
            else:
                ret += rec(i+1, k, True) # 次も0を選ぶ
                ret += rec(i+1, k-1, True) * (int(N[i]) - 1) # 0 < ?? < N[i]
                ret += rec(i+1, k-1, False) # N[i]を選ぶ、真にsmallerとは限らないのでまだFalse
        
        dp[i][k][int(smaller)] = ret
        return ret

    print(rec(0, K, False))
    
    
if __name__ == "__main__":
    resolve() def resolve():
    N = list(input())
    lenN = len(N)
    K = int(input())
    dp = [[[None, None] for _ in range(K+1)] for __ in range(lenN)]

    def rec(i, k, smaller):
        if k==0:
            return 1
        if i>=lenN:
            return 0
        
        if dp[i][k][int(smaller)] is not None:
            return dp[i][k][int(smaller)]
        
        ret = 0
        if smaller:
            ret += rec(i+1, k, True)
            ret += rec(i+1, k-1, True) * 9
        else:
            if N[i] == "0":
                ret += rec(i+1, k, False)
            else:
                ret += rec(i+1, k, True) # 次も0を選ぶ
                ret += rec(i+1, k-1, True) * (int(N[i]) - 1) # 0 < ?? < N[i]
                ret += rec(i+1, k-1, False) # N[i]を選ぶ、真にsmallerとは限らないのでまだFalse
        
        dp[i][k][int(smaller)] = ret
        return ret

    print(rec(0, K, False))
    
     resolve N = list(input()) N list(input()) list input() input lenN = len(N) lenN len(N) len N K = int(input()) K int(input()) int input() input [[None, None] for _ in range(K+1)] for __ in range(lenN) for __ in range(lenN) __ range(lenN) range lenN for __ in range(lenN) [[None, None] for _ in range(K+1)] dp = [[[None, None] for _ in range(K+1)] for __ in range(lenN)] dp [[[None, None] for _ in range(K+1)] for __ in range(lenN)] def rec(i, k, smaller):
        if k==0:
            return 1
        if i>=lenN:
            return 0
        
        if dp[i][k][int(smaller)] is not None:
            return dp[i][k][int(smaller)]
        
        ret = 0
        if smaller:
            ret += rec(i+1, k, True)
            ret += rec(i+1, k-1, True) * 9
        else:
            if N[i] == "0":
                ret += rec(i+1, k, False)
            else:
                ret += rec(i+1, k, True) # 次も0を選ぶ
                ret += rec(i+1, k-1, True) * (int(N[i]) - 1) # 0 < ?? < N[i]
                ret += rec(i+1, k-1, False) # N[i]を選ぶ、真にsmallerとは限らないのでまだFalse
        
        dp[i][k][int(smaller)] = ret
        return ret

     rec if k==0:
            return 1
         k==0 k 0 return 1 1 if i>=lenN:
            return 0
        
         i>=lenN i lenN return 0 0 if dp[i][k][int(smaller)] is not None:
            return dp[i][k][int(smaller)]
        
         dp[i][k][int(smaller)] is not None dp[i][k][int(smaller)] [k] [i] dp i k int(smaller) int smaller None return dp[i][k][int(smaller)] dp[i][k][int(smaller)] [k] [i] dp i k int(smaller) int smaller ret = 0 ret 0 if smaller:
            ret += rec(i+1, k, True)
            ret += rec(i+1, k-1, True) * 9
        else:
            if N[i] == "0":
                ret += rec(i+1, k, False)
            else:
                ret += rec(i+1, k, True) # 次も0を選ぶ
                ret += rec(i+1, k-1, True) * (int(N[i]) - 1) # 0 < ?? < N[i]
                ret += rec(i+1, k-1, False) # N[i]を選ぶ、真にsmallerとは限らないのでまだFalse
        
         smaller ret += rec(i+1, k, True) ret rec(i+1, k, True) rec i+1 i 1 k True ret += rec(i+1, k-1, True) * 9 ret rec(i+1, k-1, True) * 9 rec(i+1, k-1, True) rec i+1 i 1 k-1 k 1 True 9 if N[i] == "0":
                ret += rec(i+1, k, False)
            else:
                ret += rec(i+1, k, True) # 次も0を選ぶ
                ret += rec(i+1, k-1, True) * (int(N[i]) - 1) # 0 < ?? < N[i]
                ret += rec(i+1, k-1, False) # N[i]を選ぶ、真にsmallerとは限らないのでまだFalse
        
         N[i] == "0" N[i] N i "0" ret += rec(i+1, k, False) ret rec(i+1, k, False) rec i+1 i 1 k False ret += rec(i+1, k, True) ret rec(i+1, k, True) rec i+1 i 1 k True ret += rec(i+1, k-1, True) * (int(N[i]) - 1) ret rec(i+1, k-1, True) * (int(N[i]) - 1) rec(i+1, k-1, True) rec i+1 i 1 k-1 k 1 True int(N[i]) - 1 int(N[i]) int N[i] N i 1 ret += rec(i+1, k-1, False) ret rec(i+1, k-1, False) rec i+1 i 1 k-1 k 1 False dp[i][k][int(smaller)] = ret dp[i][k][int(smaller)] [k] [i] dp i k int(smaller) int smaller ret return ret ret i i k k smaller smaller print(rec(0, K, False)) print rec(0, K, False) rec 0 K False if __name__ == "__main__":
    resolve() __name__ == "__main__" __name__ "__main__" resolve() resolve def resolve():
    N = list(input())
    lenN = len(N)
    K = int(input())
    dp = [[[None, None] for _ in range(K+1)] for __ in range(lenN)]

    def rec(i, k, smaller):
        if k==0:
            return 1
        if i>=lenN:
            return 0
        
        if dp[i][k][int(smaller)] is not None:
            return dp[i][k][int(smaller)]
        
        ret = 0
        if smaller:
            ret += rec(i+1, k, True)
            ret += rec(i+1, k-1, True) * 9
        else:
            if N[i] == "0":
                ret += rec(i+1, k, False)
            else:
                ret += rec(i+1, k, True) # 次も0を選ぶ
                ret += rec(i+1, k-1, True) * (int(N[i]) - 1) # 0 < ?? < N[i]
                ret += rec(i+1, k-1, False) # N[i]を選ぶ、真にsmallerとは限らないのでまだFalse
        
        dp[i][k][int(smaller)] = ret
        return ret

    print(rec(0, K, False))
    
     def resolve():
    N = list(input())
    lenN = len(N)
    K = int(input())
    dp = [[[None, None] for _ in range(K+1)] for __ in range(lenN)]

    def rec(i, k, smaller):
        if k==0:
            return 1
        if i>=lenN:
            return 0
        
        if dp[i][k][int(smaller)] is not None:
            return dp[i][k][int(smaller)]
        
        ret = 0
        if smaller:
            ret += rec(i+1, k, True)
            ret += rec(i+1, k-1, True) * 9
        else:
            if N[i] == "0":
                ret += rec(i+1, k, False)
            else:
                ret += rec(i+1, k, True) # 次も0を選ぶ
                ret += rec(i+1, k-1, True) * (int(N[i]) - 1) # 0 < ?? < N[i]
                ret += rec(i+1, k-1, False) # N[i]を選ぶ、真にsmallerとは限らないのでまだFalse
        
        dp[i][k][int(smaller)] = ret
        return ret

    print(rec(0, K, False))
    
     resolve
def resolve():
    N = list(input())
    lenN = len(N)
    K = int(input())
    dp = [[[None, None] for _ in range(K+1)] for __ in range(lenN)]

    def rec(i, k, smaller):
        if k==0:
            return 1
        if i>=lenN:
            return 0
        
        if dp[i][k][int(smaller)] is not None:
            return dp[i][k][int(smaller)]
        
        ret = 0
        if smaller:
            ret += rec(i+1, k, True)
            ret += rec(i+1, k-1, True) * 9
        else:
            if N[i] == "0":
                ret += rec(i+1, k, False)
            else:
                ret += rec(i+1, k, True) # 次も0を選ぶ
                ret += rec(i+1, k-1, True) * (int(N[i]) - 1) # 0 < ?? < N[i]
                ret += rec(i+1, k-1, False) # N[i]を選ぶ、真にsmallerとは限らないのでまだFalse
        
        dp[i][k][int(smaller)] = ret
        return ret

    print(rec(0, K, False))
    
    
if __name__ == "__main__":
    resolve()