#include <bits/stdc++.h>
using ll = long long;
using namespace std;
long long table[101][10][4];
char N[1000];
long long K;
signed main() {
  cin >> N;
  cin >> K;
  for (long long i = 1; i < 10; i++) {
    table[0][i][1] = 1;
  }
  for (long long i = 1; i < 100; i++) {
    for (long long k = 1; k <= 3; k++) {
      long long sum = 0;
      for (long long j = 0; j < 10; j++) {
        sum += table[i - 1][j][k];
      }
      table[i][0][k] = sum;
    }
    for (long long j = 1; j < 10; j++) {
      table[i][j][1] = 1;
    }
    for (long long k = 2; k <= 3; k++) {
      for (long long j = 1; j < 10; j++) {
        table[i][j][k] = table[i][0][k - 1];
      }
    }
  }
  long long len = strlen(N);
  long long k = K;
  long long sum = 0;
  for (long long s = 0; s < len; s++) {
    long long i = len - s - 1;
    long long a = N[s] - '0';
    if (k == 1) {
      for (long long j = 0; j <= a; j++) {
        sum += table[i][j][k];
      }
      break;
    } else {
      for (long long j = 0; j < a; j++) {
        sum += table[i][j][k];
      }
    }
    k--;
  }
  cout << sum << endl;
}
