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

namespace ABC154 {
    public class E {
        public static void Main() {
            var maxNumberChars = Console.ReadLine();
            var notZeroCount = int.Parse(Console.ReadLine());

            var patternsCount = 0;
            //最大桁以外は単純にカウント
            for(int digit=notZeroCount; digit<maxNumberChars.Length; digit++) {
                patternsCount += (int)Math.Pow(9, notZeroCount) * Math.Max(1, digit - notZeroCount);
            }

            //最大桁は最大値を超えていないかチェックする
            patternsCount += CountIf(maxNumberChars, notZeroCount, true, true);

            Console.WriteLine(patternsCount);
        }

        private static int CountIf(IEnumerable<char> chars, int remaining, bool first, bool limited) {
            var number = (int)chars.First()-48;

            var countSum = 0;
            for (int i = first ? 1 : 0; i <= (limited?number:9); i++) {
                var nextlimit = limited && number == i;
                if (remaining == 1) countSum++;
                else countSum += CountIf(chars.Skip(1), remaining - 1, false, nextlimit);
            }
            return countSum;
        }

        private static int CountAll(IEnumerable<char> chars, int remaining, bool first) {
            return (int)Math.Pow(9, remaining) * (chars.Count() - remaining);
        }
    }
}
