#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string str;
  int count = 0;
  int count3;
  int count5;
  int count7;
  for (int j = 0; j < n; j++) {
    count3 = 0;
    count5 = 0;
    count7 = 0;
    str = to_string(j);
    for (int i = 0; i < str.size(); i++) {
      if (str.at(i) == '3') {
        count3 += 1;
      }
      if (str.at(i) == '5') {
        count5 += 1;
      }
      if (str.at(i) == '7') {
        count7 += 1;
      }
    }
    if (count3 > 0 && count5 > 0 && count7 > 0) {
      count += 1;
    }
  }
  cout << count << endl;
}
