#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
  switch (c) {
    case '0':
      return 0;
    case '1':
      return 1;
    case '2':
      return 2;
    case '3':
      return 3;
    case '4':
      return 4;
    case '5':
      return 5;
    case '6':
      return 6;
    case '7':
      return 7;
    case '8':
      return 8;
    case '9':
      return 9;
    default:
      return 0;
  }
}
int main() {
  string n;
  int k;
  cin >> n >> k;
  int l = n.length();
  long long int ans = 0;
  if (k == 1) {
    if (l == 1) {
      cout << ctoi(n[0]) << endl;
      return 0;
    } else {
      for (int i = (0); i < (l); ++i) {
        ans += 9;
      }
      ans -= 9;
      ans += ctoi(n[0]);
      cout << ans << endl;
      return 0;
    }
  } else if (k == 2) {
    if (l == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      if ((l - 1) * (l - 2) > 0) {
        ans += (l - 1) * (l - 2) * 81 / 2;
        ans += (l - 1) * 9 * ctoi(n[0]) - (9 - ctoi(n[1]));
      } else {
        ans += (l - 1) * 9 * ctoi(n[0]) - (9 - ctoi(n[1]));
      }
      cout << ans << endl;
      return 0;
    }
  } else {
    if (l <= 2) {
      cout << 0 << endl;
      return 0;
    } else {
      if ((l - 1) * (l - 2) * (l - 3) > 0) {
        ans += (l - 1) * (l - 2) * (l - 3) * 729 / 3;
        ans += (l - 1) * (l - 2) / 2 * 81 * ctoi(n[0]) - (9 - ctoi(n[1])) * 9;
      } else {
        ans += (l - 1) * (l - 2) / 2 * 81 * ctoi(n[0]) - (9 - ctoi(n[1])) * 9;
      }
      cout << ans << endl;
      return 0;
    }
  }
}
