#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long mod = 998244353;
int inf = 1000001000;
long long INF = 1e18 + 5;
int main() {
  string s;
  int k;
  cin >> s >> k;
  if (k == 1) {
    int u = s[0] - '0';
    cout << (s.size() - 1) * 9 + u << endl;
  }
  if (k == 2) {
    long long u = 0;
    if (s.size() < 2) {
      cout << 0 << endl;
      return 0;
    }
    for (int(i) = 0; (i) < (s.size() - 1); (i)++) {
      long long p = 81;
      u += p * i;
    }
    long long v = 9, c = s[0] - '0';
    u += c * v * (s.size() - 1);
    long long cc = s[1] - '0';
    u += cc - 9;
    cout << u << endl;
  }
  if (k == 3) {
    long long u = 0, b = 9;
    for (int(i) = 0; (i) < (s.size()); (i)++) {
      for (int j = 0; j < i; j++) {
        for (int k = 0; k < j; k++) {
          if (i == s.size() - 1) {
            long long e = s[0] - '0';
            if (j == s.size() - 2) {
              long long ee = s[1] - '0';
              if (k == s.size() - 3) {
                long long eee = s[2] - '0';
                u += e * ee * eee;
              } else
                u += e * ee * b;
            } else
              u += e * b * b;
          } else
            u += b * b * b;
        }
      }
    }
    cout << u << endl;
  }
}
