#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int main()
{
	string n;
	int k;
	cin>>n>>k;
	if(k==1)
	{
		ll ans=0;
		ans+=n[0]-'0';
		ans+=(n.size()-1)*9;
		cout<<ans<<endl;
		return 0;
	}
	else if(k==2)
	{
		ll ans=0;
		ans+=(n.size()-1)*(n.size()-2)/2*(ll)9*9;
		ans+=max((ll)0,(ll)n[0]-'1')*(n.size()-1)*9;
		//cout<<ans<<endl;
		int now=1;
		for(;now<n.size();now++)
		{
			if(n[now]!=0)break;
		}
		//cout<<now<<endl;
		if(now!=n.size())ans+=(n.size()-now-1)*9+(n[now]-'0');
		cout<<ans<<endl;
	}
	else if(k==3)
	{
		ll ans=0;
		ans+=(n.size()-1)*(n.size()-2)*(n.size()-3)/(ll)6*(ll)9*9*9;
		ans+=max((ll)0,(ll)n[0]-'1')*(n.size()-1)*(n.size()-2)/2*(ll)9*9;		
		//cout<<ans<<endl;
		ll now=1;
		for(;now<n.size();now++)
		{
			if(n[now]!=0)break;
		 } 
		if(now!=n.size())
		{
			ans+=(n.size()-now-1)*(n.size()-now-2)/2*(ll)9*9;
			ans+=max((ll)0,(ll)(n[now]-'1')*(n.size()-now-1)*(ll)9);
			//cout<<ans<<endl;
			now++;
			for(;now<n.size();now++)
				if(n[now]!=0)break;
			//cout<<now<<endl;
			if(now!=n.size())
			{
				ans+=(n.size()-now-1)*9+(n[now]-'0');
				//cout<<ans<<endl;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
