#include<bits/stdc++.h>
using namespace std;

long long int n,i,a[110],ans,mod,k,t,j,x;
string s;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>s;n=s.size();cin>>k;
	for (i=1;i<n+1;i++) a[i]=(s[n-i]-'0');
	ans=0;
	if (k==3)
	{
		for (i=3;i<n;i++) ans=ans+((i-1)*(i-2)*9*9*9)/2;
		for (i=1;i<n;i++) for (j=i+1;j<n;j++)
		{
			x=1;
			if (j<n-1) x=x*9*9;else
			{
				x=x*a[j];
				if (i<j-1) x=x*9;else x=x*a[i];
			}
			ans=ans+x+(a[n]-1)*81;
		}
	}
	else if (k==2)
	{
		for (i=2;i<n;i++) ans=ans+(i-1)*81;
		for (i=1;i<n;i++)
		{
			x=1;
			if (i<n-1) x=x*9;else x=x*a[i];
			ans=ans+x+(a[n]-1)*9;
		}
	}
	else ans=(n-1)*9+a[n];
	cout<<ans;
}
#include<bits/stdc++.h>
using namespace std;

long long int n,i,a[110],ans,mod,k,t,j,x;
string s;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>s;n=s.size();cin>>k;
	for (i=1;i<n+1;i++) a[i]=(s[n-i]-'0');
	ans=0;
	if (k==3)
	{
		for (i=3;i<n;i++) ans=ans+((i-1)*(i-2)*9*9*9)/2;
		for (i=1;i<n;i++) for (j=i+1;j<n;j++)
		{
			x=1;
			if (j<n-1) x=x*9*9;else
			{
				x=x*a[j];
				if (i<j-1) x=x*9;else x=x*a[i];
			}
			ans=ans+x+(a[n]-1)*81;
		}
	}
	else if (k==2)
	{
		for (i=2;i<n;i++) ans=ans+(i-1)*81;
		for (i=1;i<n;i++)
		{
			x=1;
			if (i<n-1) x=x*9;else x=x*a[i];
			ans=ans+x+(a[n]-1)*9;
		}
	}
	else ans=(n-1)*9+a[n];
	cout<<ans;
}
