#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  long long k;
  cin >> n >> k;
  if (k == 1) {
    long long ans = 0;
    for (long long i = 0; i < n.size(); i++) {
      if (i == 0) {
        ans += int(n[0] - 48);
      } else {
        ans += 9;
      }
    }
    cout << ans << endl;
    return 0;
  } else if (k == 2) {
    long long ans = 0;
    long long fnz = -1;
    if (n.size() < 2) {
      cout << 0 << endl;
      return 0;
    }
    for (long long i = 0; i < n.size() - 1; i++) {
      for (long long j = i + 1; j < n.size(); j++) {
        if (i == 0) {
          if (fnz == -1) {
            if (n[j] != '0') {
              fnz = j;
            } else {
              continue;
            }
          }
          if (fnz != -1) {
            if (j == fnz) {
              ans += int(n[j] - 48);
              ans += (int(n[0] - 48) - 1) * 9;
            } else {
              ans += int(n[0] - 48) * 9;
            }
          }
        } else {
          ans += 9 * 9;
        }
      }
    }
    cout << ans << endl;
    return 0;
  } else {
    long long ans = 0;
    long long fnz = -1;
    long long snz = -1;
    if (n.size() < 3) {
      cout << 0 << endl;
      return 0;
    }
    for (long long i = 0; i < n.size() - 2; i++) {
      for (long long j = i + 1; j < n.size() - 1; j++) {
        for (long long m = j + 1; m < n.size(); m++) {
          if (i == 0) {
            if (fnz == -1) {
              if (n[j] != '0') {
                fnz = j;
              } else {
                continue;
              }
            }
            if (fnz != -1) {
              if (snz == -1) {
                if (n[m] != '0') {
                  snz = m;
                } else {
                  continue;
                }
              }
              if (snz != -1) {
                if (j == fnz) {
                  if (m == snz) {
                    ans += int(n[m] - 48);
                    ans += (int(n[j] - 48) - 1) * 9;
                    ans += (int(n[0] - 48) - 1) * 9 * 9;
                  } else {
                    ans += int(n[j] - 48) * 9;
                    ans += (int(n[0] - 48) - 1) * 9 * 9;
                  }
                } else {
                  ans += int(n[0] - 48) * 9 * 9;
                }
              }
            }
          } else {
            ans += 9 * 9 * 9;
          }
        }
      }
    }
    cout << ans << endl;
    return 0;
  }
}
