using AtCoderBeginnerContest154.Questions;
using AtCoderBeginnerContest154.Extensions;
using AtCoderBeginnerContest154.Algorithms;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Numerics;

namespace AtCoderBeginnerContest154.Questions
{
    public class QuestionE : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            string n = inputStream.ReadLine();
            var k = inputStream.ReadInt();

            yield return GetCount(n, k);
        }

        int GetCount(string n, int k)
        {
            n = n.TrimStart('0');
            if (n == string.Empty)
            {
                n = "0";
            }

            if (k <= 0)
            {
                return 1;
            }

            var nInt = BigInteger.Parse(n);
            if (k == 1 && nInt < 1)
            {
                return 0;
            }
            if (k == 2 && nInt < 11)
            {
                return 0;
            }
            else if (k == 3 && nInt < 111)
            {
                return 0;
            }

            int sum = 0;
            var digit = n.Length;
            var maxDigit = n[0] - '0';

            // 最上位桁が0
            if (digit > k)
            {
                sum += (int)BasicAlgorithm.Combination(digit - 1, k) * Pow(9, k);
            }

            // 最上位桁が1以上maxDigit未満
            sum += (maxDigit - 1) * (int)BasicAlgorithm.Combination(digit - 1, k - 1) * Pow(9, k - 1);

            // 最上位桁がmaxDigit
            sum += GetCount(n.Substring(1), k - 1);

            return sum;
        }

        int Pow(int a, int n)
        {
            int result = 1;
            for (int i = 0; i < n; i++)
            {
                result *= a;
            }
            return result;
        }
    }
}


namespace AtCoderBeginnerContest154
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionE();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest154.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion
#region Algorithm

namespace AtCoderBeginnerContest154.Algorithms
{
    public static class BasicAlgorithm
    {
        public static long Factorial(int n)
        {
            if (n < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(n), $"{n}は0以上の整数でなければなりません。");
            }

            long result = 1;
            for (int i = 2; i <= n; i++)
            {
                result *= i;
            }
            return result;
        }

        public static long Permutation(int n, int r)
        {
            CheckNR(n, r);
            long result = 1;
            for (int i = 0; i < r; i++)
            {
                result *= n - i;
            }
            return result;
        }

        public static long Combination(int n, int r)
        {
            CheckNR(n, r);
            r = Math.Min(r, n - r);

            // See https://stackoverflow.com/questions/1838368/calculating-the-amount-of-combinations
            long result = 1;
            for (int i = 1; i <= r; i++)
            {
                result *= n--;
                result /= i;
            }
            return result;
        }

        public static long CombinationWithRepetition(int n, int r) => Combination(n + r - 1, r);

        private static void CheckNR(int n, int r)
        {
            if (n < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(n), $"{nameof(n)}は正の整数でなければなりません。");
            }
            if (r < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(r), $"{nameof(r)}は0以上の整数でなければなりません。");
            }
            if (n < r)
            {
                throw new ArgumentOutOfRangeException($"{nameof(n)},{nameof(r)}", $"{nameof(r)}は{nameof(n)}以下でなければなりません。");
            }
        }
    }
}

#endregion

#region Extensions

namespace AtCoderBeginnerContest154.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13268