#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 50;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int phi = 1e9 + 6;
char a[150];
int cc(int a, int b) {
  int ans1 = 1, ans2 = 1;
  for (int i = 1; i <= b; i++) {
    ans1 *= a;
    a--;
    ans2 *= i;
  }
  return ans1 / ans2;
}
int main() {
  int k;
  scanf("%s", a + 1);
  int n = strlen(a + 1);
  cin >> k;
  if (k == 1) {
    if (n == 1) {
      printf("%d\n", a[1] - '0');
    } else {
      int ans = 0;
      ans = a[1] - '0';
      ans += (n - 1) * 9;
      printf("%d\n", ans);
    }
  } else if (k == 2) {
    if (n <= 1) {
      printf("0\n");
    } else {
      if (n == 2) {
        printf("%d\n", (a[1] - '0' - 1) * 9 + a[2] - '0');
      } else {
        int ans = 0;
        int p = 0;
        p = a[2] - '0';
        p += 9 * (n - 2);
        ans += (a[1] - '0' - 1) * (n - 1) * 9 + p;
        int m = n - 1;
        for (int i = m; i >= 1; i--) {
          ans += 9 * (i - 1) * 9;
        }
        printf("%d\n", ans);
      }
    }
  } else if (k == 3) {
    if (n <= 2) {
      printf("0\n");
    } else {
      if (n == 3) {
        printf("%d\n", (a[1] - '0' - 1) * 81 + (a[2] - '0') * (a[3] - '0'));
      } else {
        int ans = 0;
        ans += (a[2] - '0' - 1) * (n - 2) * 9;
        ans += (a[3] - '0');
        ans += (n - 3) * 9;
        ans += (n - 4) * 81;
        ans += (a[1] - '0' - 1) * ((n - 2) * (n - 1) / 2) * 81;
        int m = n - 1;
        for (int i = m; i >= 2; i--) {
          ans += 9 * ((i - 1) * (i - 2) / 2) * 81;
        }
        printf("%d\n", ans);
      }
    }
  }
  return 0;
}
