#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1e9 + 7;
int main() {
  string N;
  cin >> N;
  int K;
  cin >> K;
  long long int ans = 0;
  long long int strlength = N.length();
  if (K == 1) {
    ans = (N[0] - '0') + 9 * (N.length() - 1);
    cout << ans << endl;
    return 0;
  } else if (K == 2) {
    for (long long int i = 0; i < strlength - 1; ++i) {
      for (long long int j = i + 1; j < strlength; ++j) {
        if (i == 0) {
          if (j == i + 1) {
            ans += (N[i] - '0' - 1) * 9 + (N[j] - '0');
          } else {
            ans += (N[i] - '0') * 9;
          }
        } else {
          ans += 81;
        }
      }
    }
    cout << ans << endl;
    return 0;
  } else {
    for (long long int i = 0; i < strlength - 2; ++i) {
      for (long long int j = i + 1; j < strlength - 1; ++j) {
        for (long long int k = 0; k < strlength; ++k) {
          if (i == 0) {
            if (j == i + 1) {
              if (k == j + 1) {
                ans +=
                    (N[i] - '0' - 1) * 81 + (N[j] - '0' - 1) * 9 + (N[k] - '0');
              } else {
                ans += (N[i] - '0' - 1) * 81 + (N[j] - '0') * 9;
              }
            } else {
              ans += (N[i] - '0' - 1) * 81;
            }
          } else {
            ans += 729;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
