#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  int K;
  cin >> N >> K;
  long long int ret = 0;
  int dig = (int)N.size() - 1;
  if (K == 1) {
    ret += 9 * dig + (N[0] - '0');
    cout << ret << endl;
  } else if (K == 2) {
    int nonzero = 0;
    for (int i = 1; i <= dig; i++) {
      if (nonzero) {
        ret += 9;
      } else if (N[i] - '0' != 0) {
        ret += N[i] - '0';
        nonzero = 1;
      }
    }
    int head = N[0] - '0';
    ret += (head - 1) * 9 * dig;
    int comb = dig * (dig - 1) / 2;
    ret += comb * 9 * 9;
    cout << ret << endl;
  } else {
    int comb = dig * (dig - 1) * (dig - 2) / 3 / 2;
    int comb2 = dig * (dig - 1) / 2;
    int head = N[0] - '0';
    ret += comb * 9 * 9 * 9;
    ret += (head - 1) * comb2 * 9 * 9;
    int fnz = 1000000, snz = 1000000;
    for (int i = 1; i <= dig; i++) {
      if (N[i] - '0' != 0) {
        fnz = i;
        break;
      }
    }
    if (fnz < dig) {
      for (int i = 1; i <= dig; i++) {
        if (N[i] - '0' != 0 && i > fnz) {
          snz = i;
          break;
        }
      }
    }
    for (int i = 1; i <= dig - 1; i++) {
      for (int j = i + 1; j <= dig; j++) {
        if (i == fnz && j == snz) {
          ret += (N[i] - '0' - 1) * 9;
          ret += N[j] - '0';
        } else if (i == fnz) {
          ret += (N[i] - '0') * 9;
        } else if (i > fnz) {
          ret += 9 * 9;
        }
      }
    }
    cout << ret << endl;
  }
  return 0;
}
