#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1e9;
const long long INFLL = 1e18;
const long long MOD = 1e9 + 7;
const double PI = acos(-1.0);
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
string N;
int K;
vector<int> n;
long long dp[100][2][200];
int main() {
  cin >> N >> K;
  for (auto a : N) {
    n.push_back(a - '0');
  }
  int l = N.size();
  dp[0][0][0] = 1;
  for (int i = 0; i < l; i++) {
    for (int smaller = 0; smaller < 2; smaller++) {
      for (int j = 0; j <= 3; j++) {
        for (int x = 0; x <= (smaller ? 9 : n[i]); x++) {
          if (x != 0) {
            dp[i + 1][smaller || x < n[i]][j + 1] += dp[i][smaller][j];
          } else {
            dp[i + 1][smaller || x < n[i]][j] += dp[i][smaller][j];
          }
        }
      }
    }
  }
  cout << dp[l][0][K] + dp[l][1][K] << endl;
  return 0;
}
