#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

/*** chmax, chmin ***/
// a < b ならば a を b で更新
// 更新されたら true を返す
template <typename T>
bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b; 
		return true;
	}
	return false;
}
// a > b ならば a を b で更新
// 更新されたら true を返す
template <typename T>
bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b; 
		return true;
	}
	return false;
}
/*** chmax, chmin ここまで ***/

void Main()
{
	string s;
    int k;
  	cin >> s >> k;
  	int d = (int)s.size();
  	if(d==1){
    	if(k==1) cout << (s[0]-'0') << endl;
      	else cout << 0 << endl;
      	return;
    } else if(d==2){
      	int n1 = s[0]-'0';
      	int n2 = s[1]-'0';
      	int n = 10*n1 + n2;
    	if(k==1) cout << n1 + 9 << endl;
      	else if(k==2) cout << n - n1 - 9 << endl;
        else cout << 0 << endl;
      return;
    }
  
  	auto f3 = [&](int x){
      	if (x <= 0) return 0;
    	return x * (x-1) * (x-2) * 3 * 9 * 9 / 2;
    };
  	auto f2 = [&](int x){
      	if (x <= 0) return 0;
    	return x * (x-1) * 9 * 9 / 2;
    };
  	auto f = [&](int x){
      	if (x <= 0) return 0;
    	return x * 9;
    };
  
	int n1 = s[0]-'0';
  	int n2 = s[1]-'0';
  	int n3 = s[2]-'0';
  	int n = 100*n1 + 10*n2 + n3;
  
 	ll ans; 
  	if(k==1){ 
      	cout << n1 + f(d-1) << endl;
    } else if(k==2) {
      ans = f2(d-1) + (n1-1)*f(d-1) + n2 + f(d-2);
      cout << ans << endl;
    } else {  
      	ans = f3(d-1) + (n1-1)*f2(d-1) + n2*f(d-2) + f2(d-2);
  		cout << ans << endl;
    }
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}
