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 C = N.Length;

            var dp = new int[C][][];
            for(int i = 0; i < C; i++)
            {
                dp[i] = new int[2][];
                for(int j = 0; j < 2; j++)
                {
                    dp[i][j] = Enumerable.Repeat(0, K + 1).ToArray();
                }
            }
            dp[0][0][0] = 1;
            dp[0][0][1] = int.Parse(N[0].ToString()) - 1;
            dp[0][1][0] = 0;
            dp[0][1][1] = 1;

            var ans0 = Rec(N, dp, C - 1, 0, K);
            var ans1 = Rec(N, dp, C - 1, 1, K);
            var ans = ans0 + ans1;

            Console.WriteLine(ans);
        }

        static int Rec(string N,int[][][] dp, int i, int j,int k)
        {
            if (i == 0)
            {
                return dp[i][j][k];
            }

            if (j == 0 && k == 0)
            {
                return Rec(N,dp, i - 1, 0, 0);
            }else if (j == 0)//&&k==k
            {
                if (N[i] == '0')
                {
                    return Rec(N, dp, i - 1, 0, k - 1) * 9 + Rec(N, dp, i - 1, 0, k);
                }
                else
                {
                    return Rec(N, dp, i - 1, 0, k - 1) * 9 + Rec(N, dp, i - 1, 0, k) + Rec(N, dp, i - 1, 1, k - 1) * (int.Parse(N[i].ToString()) - 1) + Rec(N, dp, i - 1, 1, k);
                }
            }else if(k == 0) //&& j==1
            {
                return 0;
            }
            else //k==k && j==1
            {
                if (N[i] != '0')
                {
                    return Rec(N, dp, i - 1, 1, k - 1);
                }
                else
                {
                    return Rec(N, dp, i - 1, 1, k);
                }
            }
        }


        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]);
        }
    }
}

Measured memory_bytes: 15444