#include <bits/stdc++.h>
using namespace std;
long long keta(long long x) {
  for (long long i = 0; i < 30; i++) {
    if (x < 10) {
      return i + 1;
    }
    x = x / 10;
  }
}
long long gcd(long long x, long long y) {
  long long aa = x, bb = y;
  for (long long i = 0; i < 1000; i++) {
    aa = aa % bb;
    if (aa == 0) {
      return bb;
    }
    bb = bb % aa;
    if (bb == 0) {
      return aa;
    }
  }
}
long long lcm(long long x, long long y) {
  long long aa = x, bb = y;
  for (long long i = 0; i < 1000; i++) {
    aa = aa % bb;
    if (aa == 0) {
      return x / bb * y;
    }
    bb = bb % aa;
    if (bb == 0) {
      return x / aa * y;
    }
  }
}
bool p(long long x) {
  if (x == 1) return false;
  for (long long i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0 && x != i) {
      return false;
    }
  }
  return true;
}
long long max(long long a, long long b) {
  if (a >= b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a >= b)
    return b;
  else
    return a;
}
long long n2[41];
long long nis[41];
long long nia[41];
long long mody[41];
long long nn;
long long com(long long n, long long y) {
  long long ni = 1;
  for (long long i = 0; i < 41; i++) {
    n2[i] = ni;
    ni *= 2;
  }
  long long bunsi = 1, bunbo = 1;
  for (long long i = 0; i < y; i++) bunsi = (bunsi * (n - i)) % 1000000007;
  for (long long i = 0; i < y; i++) bunbo = (bunbo * (i + 1)) % 1000000007;
  mody[0] = bunbo;
  for (long long i = 1; i < 41; i++) {
    bunbo = (bunbo * bunbo) % 1000000007;
    mody[i] = bunbo;
  }
  for (long long i = 0; i < 41; i++) nis[i] = 0;
  nn = 1000000007 - 2;
  for (long long i = 40; i >= 0; i -= 1) {
    if (nn > n2[i]) {
      nis[i]++;
      nn -= n2[i];
    }
  }
  nis[0]++;
  for (long long i = 0; i < 41; i++) {
    if (nis[i] == 1) {
      bunsi = (bunsi * mody[i]) % 1000000007;
    }
  }
  return bunsi;
}
long long gyakugen(long long n, long long y) {
  long long ni = 1;
  for (long long i = 0; i < 41; i++) {
    n2[i] = ni;
    ni *= 2;
  }
  mody[0] = y;
  for (long long i = 1; i < 41; i++) {
    y = (y * y) % 1000000007;
    mody[i] = y;
  }
  for (long long i = 0; i < 41; i++) nis[i] = 0;
  nn = 1000000007 - 2;
  for (long long i = 40; i >= 0; i -= 1) {
    if (nn > n2[i]) {
      nis[i]++;
      nn -= n2[i];
    }
  }
  nis[0]++;
  for (long long i = 0; i < 41; i++) {
    if (nis[i] == 1) {
      n = (n * mody[i]) % 1000000007;
    }
  }
  return n;
}
long long yakuwa(long long n) {
  long long sum = 0;
  for (long long i = 1; i < sqrt(n + 1); i++) {
    if (n % i == 0) sum += i + n / i;
    if (i * i == n) sum -= i;
  }
  return sum;
}
bool integer(long double n) {
  if (n == long(n))
    return true;
  else
    return false;
}
long long poow(long long y, long long n) {
  if (n == 0) return 1;
  n -= 1;
  long long ni = 1;
  for (long long i = 0; i < 41; i++) {
    n2[i] = ni;
    ni *= 2;
  }
  long long yy = y;
  mody[0] = yy;
  for (long long i = 1; i < 41; i++) {
    yy = (yy * yy) % 1000000007;
    mody[i] = yy;
  }
  for (long long i = 0; i < 41; i++) nis[i] = 0;
  nn = n;
  for (long long i = 40; i >= 0; i -= 1) {
    if (nn >= n2[i]) {
      nis[i]++;
      nn -= n2[i];
    }
  }
  for (long long i = 0; i < 41; i++) {
    if (nis[i] == 1) {
      y = (y * mody[i]) % 1000000007;
    }
  }
  return y;
}
long long minpow(long long x, long long y) {
  long long sum = 1;
  for (long long i = 0; i < y; i++) sum *= x;
  return sum;
}
long long ketawa(long long x, long long sinsuu) {
  long long sum = 0;
  for (long long i = 0; i < 100; i++)
    sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i));
  return sum;
}
long long sankaku(long long a) { return a * (a + 1) / 2; }
bool search(long long x) {
  long long n;
  long long a[n];
  long long l = 0, r = n;
  while (r - l >= 1) {
    long long i = (l + r) / 2;
    if (a[i] == x)
      return true;
    else if (a[i] < x)
      l = i + 1;
    else
      r = i;
  }
  return false;
}
using Graph = vector<vector<long long>>;
long long XOR(long long a, long long b) {
  long long ni = 1;
  for (long long i = 0; i < 41; i++) {
    n2[i] = ni;
    ni *= 2;
  }
  for (long long i = 0; i < 41; i++) nis[i] = 0;
  for (long long i = 40; i >= 0; i -= 1) {
    if (a >= n2[i]) {
      nis[i]++;
      a -= n2[i];
    }
    if (b >= n2[i]) {
      nis[i]++;
      b -= n2[i];
    }
  }
  long long sum = 0;
  for (long long i = 0; i < 41; i++) sum += (nis[i] % 2 * n2[i]);
  return sum;
}
long long a[114];
signed main() {
  string second;
  cin >> second;
  long long k;
  cin >> k;
  long long n = second.size();
  for (long long i = 0; i < n; i++) a[i] = second[i] - 48;
  if (k == 1)
    cout << 9 * (n - 1) + a[0] << endl;
  else if (k == 2) {
    long long ans = 0;
    for (long long l = 1; l < 10; l++) {
      for (long long i = 1; i < n; i++) {
        for (long long j = 1; j < i + 1; j++) {
          if (i == n - 1 && l == a[0]) {
            long long sum = 0;
            for (long long m = 1; m < j; m++) sum += a[m];
            if (sum > 0)
              ans += 9;
            else
              ans += a[j];
          } else if (i == n - 1 && l > a[0]) {
          } else
            ans += 9;
        }
      }
    }
    cout << ans << endl;
  } else {
    long long pp = 0;
    for (long long i = 0; i < 10000; i++)
      for (long long j = 0; j < 10000; j++)
        for (long long m = 0; m < 100000; m++)
          for (long long t = 0; t < 10000000; t++) pp += i + j + m + t;
    long long ans = 0;
    for (long long l = 1; l < 10; l++) {
      for (long long i = 2; i < n; i++) {
        for (long long j = 1; j < i + 1; j++) {
          for (long long m = j + 1; m < i + 1; m++) {
            if (i == n - 1 && l == a[0]) {
              long long sum1 = 0;
              for (long long t = 1; t < j; t++) sum1 += a[t];
              long long sum2 = 0;
              for (long long t = 1; t < m; t++) sum2 += a[t];
              if (sum1 > 0 && sum2 > 0)
                ans += 81;
              else if (sum2 > 0) {
                if (m == j + 1)
                  ans += 9 * (a[j] - 1) + a[m];
                else
                  ans += 9 * a[j];
              } else
                ans += a[j] * a[m];
            } else if (i == n - 1 && l > a[0]) {
            } else
              ans += 81;
          }
        }
      }
    }
    cout << ans << endl;
  }
}
