#include <bits/stdc++.h>
using namespace std;
long long INFl = 1e+18 + 1;
int INF = 1e+9 + 1;
template <typename TypeInt>
std::string Itoa(const TypeInt v, int base) {
  static const char table[] = "0357ZZ";
  string ret;
  static numeric_limits<TypeInt> t;
  TypeInt n = v;
  if (t.is_signed) {
    if (v < 0) n *= -1;
  }
  while (n >= base) {
    ret += table[n % base];
    n /= base;
  }
  ret += table[n];
  if (t.is_signed) {
    if (v < 0 && base == 10) ret += '-';
  }
  std::reverse(ret.begin(), ret.end());
  return ret;
}
bool ok(int n) {
  int count[10] = {};
  while (n) {
    if (n % 10 == 3 || n % 10 == 5 || n % 10 == 7) {
      count[n % 10]++;
    } else {
      return false;
    }
    n /= 10;
  }
  if (count[3] * count[5] * count[7] > 0)
    return true;
  else
    return false;
}
int main() {
  long long N;
  cin >> N;
  int ans = 0;
  long long kazu = 0;
  for (int i = 1; kazu <= N; i++) {
    kazu = stol(Itoa(i, 4));
    if (ok(kazu)) ans++;
  }
  cout << ans << endl;
  return 0;
}
