#include <bits/stdc++.h>
using namespace std;
const int M = 110;
char s[M];
int main(int argc, char const *argv[]) {
  scanf("%s", s + 1);
  int k;
  cin >> k;
  int len = strlen(s + 1);
  long long ans = 0;
  if (k == 1) {
    ans = (len - 1) * 9 + s[1] - '0';
  } else if (k == 2) {
    for (int i = 1; i <= len; i++) {
      for (int j = i + 1; j <= len; j++) {
        int aa = s[i] - '0';
        int bb = s[j] - '0';
        if (i == 1)
          ans += (aa - 1) * 9 + bb;
        else
          ans += 81;
      }
    }
  } else {
    for (int i = 1; i <= len; i++) {
      for (int j = i + 1; j <= len; j++) {
        for (int z = j + 1; z <= len; z++) {
          if (i == 1) {
            int aa = s[i] - '0';
            int bb = s[j] - '0';
            int cc = s[z] - '0';
            ans += (aa - 1) * 81 + bb * cc;
          } else
            ans += 9 * 9 * 9;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
