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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = Read();
            var k = Read().ToInt();
            decimal ans = 0;
            if (n.Length < k)
            {
                WriteRead(0);
                return;
            }
            if (k == 1)
            {
                ans = k1(n.ToString());
            }
            else if (k == 2)
            {
                ans = k2(n.ToString());
            }
            else if (k == 3)
            {
                ans = 9 * 9 * 9 * Combination(n.Length - 1, 3);
                ans += (n[0].ToDecimal() - 1) * Combination((n.Length - 1), 2) * 9 * 9;
                ans += k2(Remove(n.ToString().Remove(0, 1)));
            }
            WriteRead(ans);
        }

        private static string Remove(string n)
        {
            var tmp = n;
            if (string.IsNullOrEmpty(tmp)) return tmp;
            bool isDel = true;
            while (isDel)
            {
                if (tmp.Length == 0) break;
                if (tmp[0] == '0')
                {
                    tmp = tmp.ToString().Remove(0, 1);
                }
                else
                {
                    isDel = false;
                }
            }
            return tmp;
        }

        private static decimal k1(string value)
        {
            if (string.IsNullOrEmpty(value)) return 0;
            decimal ans = 0;
            ans = 9 * (value.Length - 1);
            ans += value[0].ToDecimal();
            return ans;
        }

        private static decimal k2(string n)
        {
            if (string.IsNullOrEmpty(n)) return 0;
            decimal ans = 0;
            ans = 9 * 9 * Combination(n.Length - 1, 2);
            ans += (n[0].ToDecimal() - 1) * (n.Length - 1) * 9;
            ans += k1(Remove(n.ToString().Remove(0,1)));
            return ans;
        }

        private static long mod = 1000000007;

        public static long ModPow(long x, long n)
        {
            x = x % mod;
            if (n == 0)
            {
                return 1;
            }
            else if (n % 2 == 1)
            {
                return (x * ModPow(x, n - 1)) % mod;
            }
            else
            {
                return ModPow((x * x) % mod, n / 2) % mod;
            }
        }

        public static long Combination(long n, long k)
        {
            long x = 1;
            for (long i = n - k + 1; i <= n; i++)
            {
                x = x * i % mod;
            }
            long y = 1;
            for (int i = 1; i <= k; i++)
            {
                y = y * i % mod;
            }
            y = ModPow(y, mod - 2);
            return x * y % mod;
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 13268