#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(int argc, const char* argv[]) {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 357; i <= n; i++) {
    string s = to_string(i);
    if (s.find("3") != -1 && s.find("5") != -1 && s.find("7") != -1) {
      cnt++;
    }
  }
  cout << cnt << endl;
}
