#include <bits/stdc++.h>
using namespace std;
long long int dp0[101][4];
long long int dp1[101][4];
int main() {
  string s;
  int k;
  cin >> s >> k;
  int keta = s.length();
  int n[keta];
  for (int i = 0; i < keta; i++) {
    n[i] = s[i] - 48;
  }
  memset(dp0, 0, sizeof(dp0));
  memset(dp1, 0, sizeof(dp1));
  dp0[0][0] = 1;
  dp0[0][1] = n[0] - 1;
  dp1[0][1] = 1;
  for (int i = 1; i < keta; i++) {
    int mark;
    if (n[i]) {
      mark = 1;
    } else {
      mark = 0;
    }
    dp0[i][0] = dp0[i - 1][0];
    dp0[i][1] = dp0[i - 1][0] * 9 + dp0[i - 1][1] + dp1[i - 1][1] * mark;
    dp0[i][2] = dp0[i - 1][1] * 9 + dp0[i - 1][2] + dp1[i - 1][2] * mark +
                dp1[i - 1][1] * (n[i] - 1);
    dp0[i][3] = dp0[i - 1][2] * 9 + dp0[i - 1][3] + dp1[i - 1][3] * mark +
                dp1[i - 1][2] * (n[i] - 1);
    if (n[i] > 0) {
      dp1[i][1] = 0;
      dp1[i][2] = dp1[i - 1][1];
      dp1[i][3] = dp1[i - 1][2];
    } else {
      dp1[i][1] = dp1[i - 1][1];
      dp1[i][2] = dp1[i - 1][2];
      dp1[i][3] = dp1[i - 1][3];
    }
  }
  cout << dp0[keta - 1][k] + dp1[keta - 1][k] << endl;
  return 0;
}
