#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long N;
  cin >> N;
  bool flag3 = false;
  bool flag5 = false;
  bool flag7 = false;
  bool flag_ex = false;
  unsigned long long ans = 0;
  for (unsigned long long count = 357; count <= N; count++) {
    string count_s = to_string(count);
    unsigned long long size = count_s.size();
    for (unsigned long long n = 0; n < size; n++) {
      if (count_s[n] == '7') {
        flag7 = true;
      } else if (count_s[n] == '5') {
        flag5 = true;
      } else if (count_s[n] == '3') {
        flag3 = true;
      } else {
        flag_ex = true;
      }
    }
    if (flag3 && flag5 && flag7 && !flag_ex) {
      ans++;
    }
    flag3 = false;
    flag5 = false;
    flag7 = false;
    flag_ex = false;
  }
  cout << ans << endl;
  return 0;
}
