#include <bits/stdc++.h>
using namespace std;
char arr[200];
char tmp[200];
void solve() {
  scanf("%s", arr);
  int k;
  scanf("%d", &k);
  int n = strlen(arr);
  int ans = 0;
  if (k == 1) {
    ans += 9 * (n - 1);
    ans += arr[0] - '0';
  }
  tmp[n] = 0;
  for (int i = 0; i < n; i++) tmp[i] = '0';
  if (k == 2) {
    if (n - 1 >= 2) {
      ans += (n - 1) * (n - 2) / 2 * 9 * 9;
    }
    if (n >= 2) {
      for (int i = 1; i <= 9; i++) {
        tmp[0] = i + '0';
        for (int z = 1; z < n; z++) {
          for (int j = 1; j <= 9; j++) {
            tmp[z] = j + '0';
            if (strcmp(arr, tmp) >= 0) {
              ans++;
            }
          }
          tmp[z] = '0';
        }
        tmp[0] = '0';
      }
    }
  }
  if (k == 3) {
    if (n - 1 >= 3) {
      ans += (n - 1) * (n - 2) * (n - 3) / 6 * 9 * 9 * 9;
    }
    if (n >= 3) {
      for (int i = 1; i <= 9; i++) {
        tmp[0] = i + '0';
        for (int z = 1; z < n; z++) {
          for (int y = z + 1; y < n; y++) {
            for (int j = 1; j <= 9; j++) {
              tmp[z] = j + '0';
              for (int kk = 1; kk <= 9; kk++) {
                tmp[y] = kk + '0';
                if (strcmp(arr, tmp) >= 0) {
                  ans++;
                }
                tmp[y] = '0';
              }
              tmp[z] = '0';
            }
          }
        }
        tmp[0] = '0';
      }
    }
  }
  printf("%d\n", ans);
}
void init() {}
int main() {
  init();
  solve();
  return 0;
}
