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

namespace CSharpSample01
{


	class Program
	{
		static void Main(string[] args)
		{
			var N = double.Parse(Console.ReadLine());
			var K = int.Parse(Console.ReadLine());
			var startLine = 10 * K;
			var defaultValue = 0;
			var line = 0;

			//			var defaultValue = 9 ^ K;
			if (K == 1)
			{
				defaultValue = 9;
				line = 10;
			}
			else if (K == 2)
			{
				defaultValue = 81;
				line = 100;
			}
			else
			{
				defaultValue = 81 * 9;
				line = 1000;
			}

			var answer = 1;
			var addValue = 0;
			//			if (N < 10 ^ K)
			if (N <= line)
			{
				for (double i = 1; i <= N; i++)
				{
					var notZero = i.ToString().Count(x => x != '0');
					if (notZero == K)
						answer++;
				}

				Console.WriteLine(answer);
			}
			else
			{
				while(true)
				{
					startLine = startLine * 10;
					if (startLine < N)
					{
						answer++;
					}
					else
					{
						startLine = startLine / 10;
						for (double i = startLine; i <= N; i++)
						{
							var notZero = i.ToString().Count(x => x != '0');
							if (notZero == K)
								addValue++;
						}
						break;
					}
				}

				Console.WriteLine((answer) * defaultValue + addValue);
			}

		}


	}
}