#include <bits/stdc++.h>
using namespace std;
long long dp3(long long n) { return 121.5 * (n) * (n - 1) * (n - 2); }
long long dp2(long long n) { return 40.5 * (n) * (n - 1); }
long long dp1(long long n) { return 9 * n; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    string sp, s = "";
    long long k;
    cin >> sp >> k;
    long long n = sp.size(), k1, k2, k3, c = 0, z = 0, b = 0, flag1 = 1,
              flag2 = 1, flag3 = 1;
    for (long long i = 0; i < n; ++i) {
      if (sp[i] != '0') {
        z++;
      }
    }
    if (k == 3) {
      if (z == 1) {
        if (sp.size() >= 4) {
          s += to_string(((sp[0] - '0') - 1));
          for (long long i = 0; i < sp.size() - 1; ++i) {
            s += '9';
            flag1 = 0;
          }
        } else {
          cout << 0;
          return 0;
        }
      } else if (z == 2) {
        flag2 = 0;
        for (long long i = n - 1; i >= 0; --i) {
          if (sp[i] != '0') {
            b = i;
            break;
          }
        }
        if (b >= (n - 2)) {
          s += to_string(((sp[0] - '0') - 1));
          for (long long i = 0; i < sp.size() - 1; ++i) {
            s += '9';
          }
        } else {
          for (long long i = 0; i < b; ++i) {
            s += sp[i];
          }
          s += to_string(((sp[b] - '0') - 1));
          for (long long i = b; i < sp.size() - 1; ++i) {
            s += '9';
          }
        }
      }
    } else if (k == 2) {
      if (z == 1) {
        flag3 = 0;
        if (sp.size() >= 3) {
          s += to_string(((sp[0] - '0') - 1));
          for (long long i = 0; i < sp.size() - 1; ++i) {
            s += '9';
          }
        } else {
          cout << 0;
          return 0;
        }
      }
    }
    if (flag1 * flag2 * flag3) {
      for (long long i = 0; i < n; ++i) {
        s += sp[i];
      }
    }
    for (long long i = 0; i < n; ++i) {
      if (s[i] != '0') {
        c++;
        if (c == 1) {
          k1 = i;
        } else if (c == 2) {
          k2 = i;
        } else if (c == 3) {
          k3 = i;
        }
      }
    }
    if (k == 3) {
      long long n1 = n - k1, n2 = n - k2, n3 = n - k3;
      cout << dp3(n1 - 1) + (dp2(n1 - 1) * ((s[k1] - '0') - 1)) + dp2(n2 - 1) +
                  (dp1(n2 - 1) * ((s[k2] - '0') - 1)) +
                  ((s[k3] - '0') * n3 + (9 - (s[k3] - '0')) * (n3 - 1));
    } else if (k == 2) {
      long long n1 = n - k1, n2 = n - k2;
      cout << dp2(n1 - 1) + dp1(n1 - 1) * ((s[k1] - '0') - 1) +
                  (s[k2] - '0') * n2 + (9 - (s[k2] - '0')) * (n2 - 1);
    } else {
      long long n1 = n - k1;
      cout << (s[k1] - '0') * n1 + (9 - (s[k1] - '0')) * (n1 - 1);
    }
  }
  return 0;
}
