#include <bits/stdc++.h>
using namespace std;
bool shichigosan(int i) {
  bool seven = false;
  bool five = false;
  bool three = false;
  while (i > 0) {
    auto j = i % 10;
    if (j == 7) {
      seven = true;
    } else if (j == 5) {
      five = true;
    } else if (j == 3) {
      three = true;
    } else {
      return false;
    }
    i /= 10;
  }
  return seven && five && three;
}
int main() {
  int N;
  cin >> N;
  int count = 0;
  for (int i = 1; i <= N; ++i) {
    if (shichigosan(i)) {
      ++count;
    }
  }
  cout << count << endl;
  return 0;
}
