#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  string s, s2;
  cin >> s;
  ll l = s.size();
  ll ans = 0;
  int k;
  cin >> k;
  if (k == 1) {
    for (int i = 0; i < (10); ++i) {
      if (i != 0) {
        s2 = s[0];
        if (i <= atoi(s2.c_str())) {
          ans += l;
        } else {
          ans += (l - 1);
        }
      }
    }
    cout << ans << endl;
  } else if (k == 2 and l >= 2) {
    for (int i = 0; i < (10); ++i) {
      if (i != 0) {
        s2 = s[0];
        if (i < atoi(s2.c_str())) {
          ans += 9 * l * (l - 1) / 2;
        } else if (i == atoi(s2.c_str())) {
          ans += 9 * (l - 1) * (l - 2) / 2;
          for (int j = 0; j < (10); ++j) {
            if (j != 0) {
              s2 = s[1];
              if (j <= atoi(s2.c_str())) {
                ans += l - 1;
              } else {
                ans += l - 2;
              }
            }
          }
        } else {
          ans += 9 * (l - 1) * (l - 2) / 2;
        }
      }
    }
    cout << ans << endl;
  } else if (k == 3 and l >= 3) {
    for (int i = 0; i < (10); ++i) {
      if (i != 0) {
        s2 = s[0];
        if (i < atoi(s2.c_str())) {
          ans += 81 * l * (l - 1) * (l - 2) / 6;
        } else if (i == atoi(s2.c_str())) {
          ans += 81 * (l - 3) * (l - 1) * (l - 2) / 6;
          for (int j = 0; j < (10); ++j) {
            if (j != 0) {
              s2 = s[1];
              if (j < atoi(s2.c_str())) {
                ans += 9 * (l - 1) * (l - 2) / 2;
              } else if (j == atoi(s2.c_str())) {
                ans += 9 * (l - 2) * (l - 3) / 2;
                for (int ii = 0; ii < (10); ++ii) {
                  if (ii != 0) {
                    s2 = s[2];
                    if (ii <= atoi(s2.c_str())) {
                      ans += l - 2;
                    } else {
                      ans += l - 3;
                    }
                  }
                }
              } else {
                ans += 9 * (l - 2) * (l - 3) / 2;
              }
            }
          }
        } else {
          ans += 81 * (l - 3) * (l - 1) * (l - 2) / 6;
        }
      }
    }
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}
