#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[110];
  int k, n, ans = 0;
  scanf("%s", s);
  scanf("%d", &k);
  n = strlen(s);
  if (n < k) {
    printf("0\n");
    return 0;
  }
  if (k == 1) {
    for (int i = 1; i < 10; i++) {
      for (int j = 0; j < n - 1; j++) {
        ans++;
      }
      if (s[0] - '0' >= i) {
        ans++;
      }
    }
  } else if (k == 2) {
    for (int i = 11; i <= 99; i++) {
      if (i % 10) {
        int a = i / 10;
        int b = i % 10;
        if (a < s[0] - '0' || (a == s[0] - '0' && b <= s[1] - '0')) {
          int x = n * (n - 1) / 2;
          ans += x;
        } else if (a == s[0] - '0' && b > s[1] - '0') {
          int x = n * (n - 1) / 2;
          ans += x - 1;
        } else if (a > s[0] - '0') {
          int x = (n - 1) * (n - 2) / 2;
          ans += x;
        } else {
          return 0;
        }
      }
    }
  } else if (k == 3) {
    for (int i = 111; i <= 999; i++) {
      int a = i / 100;
      int b = i / 10 % 10;
      int c = i % 10;
      if (b && c) {
        if (a < s[0] - '0' || (a == s[0] - '0' && b < s[1] - '0') ||
            (a == s[0] - '0' && b == s[1] - '0' && c <= s[2] - '0')) {
          int x = n * (n - 1) * (n - 2) / 6;
          ans += x;
        } else if (a == s[0] - '0' && b > s[1] - '0') {
          int x = n * (n - 1) * (n - 2) / 6;
          ans += x;
          ans -= n - 2;
        } else if (a == s[0] - '0' && b == s[1] - '0' && c > s[2] - '0') {
          int x = n * (n - 1) * (n - 2) / 6;
          ans += x;
          ans--;
        } else if (a > s[0] - '0') {
          ans += (n - 1) * (n - 2) * (n - 3) / 6;
        } else {
          return 0;
        }
      }
    }
  }
  printf("%d\n", ans);
}
