#include <bits/stdc++.h>
#include "../lib/math/comb.hpp"

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  Combination<MOD> comb(100000);

  string s; cin >> s;
  int k; cin >> k;
  int dig = SZ(s);
  vector<int> a(dig);
  for(int i=0;i<dig;++i) {
    a[i] = s[i] - '0';
  }

  ll ans = 0;
  ll mul = 1;
  for(int i=0;i<k;++i) {
    mul *= 9;
  }
  for(int i=k;i<dig;++i) {
    ans += mul * comb.C(i-1, k-1);
  }

  vector<vector<vector<ll>>> dp(dig, vector<vector<ll>>(k+1, vector<ll>(2, 0)));
  if(a[0] > 0) {
    dp[0][1][1] = 1;
    dp[0][1][0] = a[0] - 1;
  }

  for(int i=0;i<dig-1;++i) {
    for(int j=0;j<k+1;++j) {
      dp[i+1][j][0] += dp[i][j][0]; // 0えらぶ
      if(j > 0) dp[i+1][j][0] += 9 * dp[i][j-1][0]; // 0以外えらぶ
      if(a[i+1] > 0) {
        dp[i+1][j][0] += dp[i][j][1]; // 0えらぶ
        if(j > 0) dp[i+1][j][0] += (a[i+1]-1) * dp[i][j-1][1]; // 0以外えらぶ
      }

      if(a[i+1] == 0) dp[i+1][j][1] += dp[i][j][1]; // ちょうど
      else if(j > 0) dp[i+1][j][1] += dp[i][j-1][1]; // ちょうど
    }
  }



  ans += dp[dig-1][k][1] + dp[dig-1][k][0];


  cout << ans << endl;
}
