#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  string s;
  int ans = 0;
  map<char, int> dict;
  for (int i = 1; i <= N; ++i) {
    s = to_string(i);
    for (int j = 0; j < s.length(); ++j) {
      ++dict[s[j]];
    }
    if (dict.size() != 3) {
      continue;
    }
    auto ite = dict.begin();
    if (ite->first != '3') {
      continue;
    }
    ++ite;
    if (ite->first != '5') {
      continue;
    }
    ++ite;
    if (ite->first != '7') {
      continue;
    }
    ++ans;
  }
  cout << ans;
  return 0;
}
