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

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			//Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
			sw.Start();


			string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			int K = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int[] N = new int[s.Length];
			for (int i = 0; i < s.Length; i++) {
				N[i] = int.Parse(s[i].ToString());
			}

			int[] idx = { s.Length - 1, s.Length - 2, s.Length - 3 };
			long ans = 0;
			int[] val = new int[s.Length];
			while (true) {
				int p = 9;
				if (K == 2) {
					p = 81;
				} else if (K == 3) {
					p = 729;
				}
				for (int i = 0; i < p; i++) {
					val[idx[0]] = i % 9 + 1;
					if (K >= 2) { val[idx[1]] = i / 9 % 9 + 1; }
					if (K >= 3) { val[idx[2]] = i / 81 % 9 + 1; }
					if (Check(N, val)) {
						ans++;
						//System.Diagnostics.Debug.WriteLine(string.Join("", val));
					} else {
						break;
					}
				}
				val[idx[0]] = 0;
				if (K >= 2) { val[idx[1]] = 0; }
				if (K >= 3) { val[idx[2]] = 0; }

				idx[0]--;
				if (idx[0] < 0) { break; }
				if (K >= 2 && idx[0] == idx[1]) {
					idx[1]--;
					idx[0] = s.Length - 1;
					if (idx[1] < 0) { break; }
				}
				if (K >= 3 && idx[1] == idx[2]) {
					idx[2]--;
					idx[1] = s.Length - 2;
					idx[0] = s.Length - 1;
					if (idx[2] < 0) { break; }
				}
			}
			Console.WriteLine(ans);


			sw.Stop();
			System.Diagnostics.Debug.WriteLine($"{sw.ElapsedMilliseconds}msec");


			//Console.Out.Flush();
		}

		static bool Check(int[] x, int[] y)
		{
			for (int i = 0; i < x.Length; i++) {
				if (x[i] > y[i]) { return true; }
				if (x[i] < y[i]) { return false; }
			}
			return true;
		}

	}
}
