using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var N = GetStr();
            var K = GetInt();
            var ans = Hoge(N, K);

            Console.WriteLine(ans);
        }

        static long Hoge(string N,int K)
        {
            var len = N.Length;
            long ans = 0;
            var first = int.Parse(N[0].ToString());
            if (K == 1)
            {
                ans = 9 * (len - 1) + long.Parse(N[0].ToString());
            }
            else if (K == 2)
            {
                for (int i = 1; i < len - 1; i++)
                {
                    ans += 9 * 9 * i;
                }
                ans += (first - 1) * 9 * (len - 1);
                if (len > 1)
                {
                    ans += Hoge(N.Substring(1, len - 1), 1);
                }
            }
            else
            {
                for(int i = 2; i < len - 1; i++)
                {
                    ans += 9 * 9 * 9 * Conbination(i, 2);
                }
                ans += (first - 1) * 9 * 9 * Conbination(len - 1, 2);
                if (len > 2)
                {
                    ans += Hoge(N.Substring(1, len - 1),2);
                }
            }


            return ans;
        }

        static long Conbination(long n, long m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * Conbination(n - 1, m - 1) / m;
        }


        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}