using System;
class ProgramE
    {
        static void Main(string[] args)
        {
            
            //入力
            string n = Console.ReadLine();
            int k = int.Parse(Console.ReadLine());

            int keta = n.Length;
            int sum = 0;

            for(int i = 0; i < n.Length; i++)
            {
                int temp = n[i] -'0';

                if(k == 1)
                {
                    if(i == 0)
                        sum += temp;
                    else
                        sum += 9;
                }
                else if(k == 2)
                {
                    if(i == 0)
                        sum = (keta -1) * (temp -1) * 9;
                    else
                        sum += (keta -1) * 81;

                    if(i == 1)
                        sum += temp + (keta -1)* 9;
                        

                }
                else
                {
                    if(i == 0)
                        sum = (keta -1) * (keta -2) / 2 * (temp - 1) * 9 * 9;
                    else
                        sum += (keta -1) * (keta -2) / 2 * 9*9*9; 

                    if(i == 1)
                        sum += (temp -1) * (keta -1) * 9+ (keta -1)*(keta -2) / 2 * 9*9;

                    if(i == 2)
                        sum += temp + (keta -1)*9;
                    
                }

                keta--;

            }
            Console.WriteLine(sum);
            
        } 
    }