#include <bits/stdc++.h>
int N;
int digits(int N) {
  int ans = 1;
  while (N / 10 != 0) {
    ans++;
    N /= 10;
  }
  return ans;
}
bool check(int N) {
  int digit = digits(N);
  bool seven = false;
  bool five = false;
  bool three = false;
  bool violation = false;
  for (int i = 0; i < digit; ++i) {
    int temp = N % 10;
    if (temp == 3)
      three = true;
    else if (temp == 5)
      five = true;
    else if (temp == 7)
      seven = true;
    else
      violation = true;
    N /= 10;
  }
  return seven && five && three && !violation;
}
int main() {
  std::cin >> N;
  int ans = 0;
  for (int i = 357; i <= N; ++i) {
    if (check(i)) ans++;
  }
  std::cout << ans << std::endl;
}
