#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  long long int k, i;
  cin >> s;
  cin >> k;
  long long int L = s.length();
  if (k == 1) {
    long long int sum;
    if (L == 1) {
      sum = (long long int)s[0] - 48;
    } else {
      sum = 9;
      for (i = 2; i <= L - 1; i++) {
        sum += 9;
      }
      sum += (long long int)s[0] - 48;
    }
    cout << sum;
  } else {
    if (k == 2) {
      long long int sum;
      if (L == 1) {
        sum = 0;
      } else {
        if (L == 2) {
          long long int x = (long long int)s[0] - 48;
          long long int y = (long long int)s[1] - 48;
          x -= 1;
          sum = (x * 9) + (1 * y);
        } else {
          sum = 81;
          for (i = 3; i <= L - 1; i++) {
            sum += ((i - 1) * 81);
          }
          long long int x = (long long int)s[0] - 48;
          x -= 1;
          sum += x * (L - 1) * 9;
          long long int f = 0;
          for (i = 1; i < L; i++) {
            if (s[i] != '0') {
              f = 1;
              break;
            }
          }
          if (f == 1) {
            long long int y = (long long int)s[1] - 48;
            sum += ((L - i - 1) * 9) + y;
          }
        }
      }
      cout << sum;
    } else {
      long long int sum;
      if (L == 1) {
        sum = 0;
      } else {
        if (L == 2) {
          sum = 0;
        } else {
          if (L == 3) {
            long long int x = (long long int)s[0] - 48;
            long long int y = (long long int)s[1] - 48;
            long long int z = (long long int)s[2] - 48;
            sum = ((x - 1) * 81) + (1 * (((y - 1) * 9) + (1 * z)));
          } else {
            sum = 729;
            for (i = 4; i <= L - 1; i++) {
              sum += (9 * (((i - 2) * (i - 1)) / 2) * 81);
            }
            long long int x = (long long int)s[0] - 48;
            x -= 1;
            sum += (x * (((L - 1) * (L - 2)) / 2) * 81);
            long long int f = 0;
            for (i = 1; i < L; i++) {
              if (s[i] != '0') {
                f = 1;
                break;
              }
            }
            if (f == 1) {
              long long int k = L - i - 1;
              if (k >= 2) {
                sum += ((k * (k - 1)) / 2) * 81;
              }
              long long int o = (long long int)s[i] - 48;
              sum += (o - 1) * (k * 9);
              for (long long int j = i + 1; j < L; j++) {
                sum += (long long int)s[j] - 48;
              }
            }
          }
        }
      }
      cout << sum;
    }
  }
  return 0;
}
