#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int stack[20];
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (!x) {
    putchar('0');
    return;
  }
  int top = 0;
  while (x) stack[++top] = x % 10, x /= 10;
  while (top) putchar(stack[top--] + '0');
}
inline void pr1(int x) { write(x), putchar(' '); }
inline void pr2(int x) { write(x), puts(""); }
char ss[110];
int main() {
  scanf("%s", ss + 1);
  int len = strlen(ss + 1);
  int n = read();
  if (n == 1)
    pr2(ss[1] - '0' + (len - 1) * 9);
  else if (n == 2) {
    int ans = 0;
    for (int i = 2; i <= len; i++) {
      if (i < len)
        ans += 9 * (i - 1) * 9;
      else
        ans += (ss[1] - '0' - 1) * (i - 1) * 9 + (i - 2) * 9 + ss[2] - '0';
    }
    pr2(ans);
  } else {
    int ans = 0;
    for (int i = 2; i <= len; i++) {
      for (int j = i + 1; j <= len; j++) {
        if (j < len)
          ans += 9 * 9 * 9 * (i - 1);
        else {
          for (int k = 1; k <= ss[1] - '0'; k++) {
            if (k < ss[1])
              ans += 9 * 9 * (i - 1);
            else {
              if (i == len - 1)
                ans +=
                    (ss[2] - '0' - 1) * 9 * (i - 1) + 9 * (i - 2) + ss[3] - '0';
              else
                ans += 9 * 9 * (i - 1);
            }
          }
        }
      }
    }
    pr2(ans);
  }
  return 0;
}
