#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 7;
char a[107];
int k;
long long sum = 0;
int main() {
  scanf("%s%d", a, &k);
  int s = strlen(a);
  if (k == 1) {
    for (int i = 0; i < s; i++) {
      int x = a[i] - '0';
      if (i != 0) x = 9;
      sum += x;
    }
  } else if (k == 2) {
    int f = 0;
    for (int i = 0; i < s; i++) {
      for (int j = i + 1; j < s; j++) {
        int x = a[i] - '0', y = a[j] - '0';
        if (f) {
          y = 9;
          if (i != 0) x = 9;
        }
        if (a[j] - '0') f = 1;
        sum += max(0, (x - 1) * 9 + y);
      }
      f = 1;
    }
  } else {
    int f1 = 0, f2 = 0;
    for (int i = 0; i < s; i++) {
      for (int j = i + 1; j < s; j++) {
        for (int p = j + 1; p < s; p++) {
          int x = a[i] - '0', y = a[j] - '0', z = a[p] - '0';
          if (f1) {
            z = 9;
            if (i != 0) x = 9;
            if (f2) y = 9;
          }
          if (a[p] - '0') f1 = 1;
          sum += max(0, (x - 1) * 81 + (y - 1) * 9 + z);
        }
        f1 = 1;
        if (a[j] - '0') f2 = 1;
      }
      f1 = f2 = 1;
    }
  }
  printf("%lld\n", sum + 1);
  return 0;
}
