
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0;i < (n);i++)
using namespace std;
typedef long long ll;

]

int main() {
  ll N, K;
  cin >> N >> K;
  string s = to_string(N);
  ll dp[105][2][4];

  rep(i,105) {
    rep(smaller, 2) {
      rep(k, 2){
        dp[i][smaller][k] = 0;
      }
    }
  }

  dp[0][0][0] = 1;  
  rep(i,s.size()) {
    rep(smaller, 2) {
      rep(k, 4){
        int c_ = s[i] - '0';
        rep(c,10) {
          int i_ = i+1;
          int smaller_ = smaller;
          int k_ = k;

          if( c != 0) {
            k_++;
          }
          if(k_ > K) {
            continue;
          }

          if(smaller_ == 0) {
            if(c_ < c) {
              continue;
            }else if(c < c_) {
              smaller_ = 1;
            }
          }
          dp[i_][smaller_][k_] += dp[i][smaller][k];
        }
      }
    }
  }
  cout << dp[s.size()][0][K] + dp[s.size()][1][K] << endl;
}