#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int len = s.length();
  int k;
  cin >> k;
  long long ans = 0;
  if (k == 1) {
    for (int i = 1; i < len; i++) {
      ans += 9;
    }
    int j = int(s[0]) - 48;
    ans += j;
  } else if (k == 2) {
    for (int i = 2; i < len; i++) {
      ans += (81 * (i - 1));
    }
    int j = int(s[0]) - 48;
    int flag = 0;
    for (int i = 1; i < len; i++) {
      if (s[i] != '0') {
        flag++;
        break;
      }
    }
    if (flag == 0) {
      if (j != 1) {
        ans += ((j - 1) * (len - 1) * 9);
      }
    } else {
      long long b = 0;
      flag = len;
      ans += (((len - 1) * 9) * (j - 1));
      for (int i = len - 1; i >= 1; i--) {
        if (s[i] != '0') {
          flag = i;
        }
      }
      b = int(s[flag]) - 48;
      ans += (len - flag - 1) * 9;
      ans += b;
    }
  } else {
    for (int i = 3; i < len; i++) {
      ans += (9 * ((i - 1) * (i - 2) / 2) * 81);
    }
    int j = int(s[0]) - 48;
    int flag = 0;
    for (int i = 1; i < len; i++) {
      if (s[i] != '0') {
        flag++;
        break;
      }
    }
    if (flag == 0) {
      if (j != 0) {
        ans += ((j - 1) * ((len - 1) * (len - 2) / 2) * 81);
      }
    } else {
      long long b = 0;
      flag = len;
      ans += (j - 1) * ((len - 1) * (len - 2) / 2) * 81;
      for (int i = len - 1; i >= 1; i--) {
        if (s[i] != '0') {
          flag = i;
        }
      }
      if (flag != len - 1) {
        b = int(s[flag]) - 48;
        int q = len - flag - 1;
        ans += 81 * (q * (q - 1) / 2);
        ans += b * q * 9;
      }
    }
  }
  cout << ans << endl;
}
