#include <bits/stdc++.h>
int main() {
  long long N;
  std::cin >> N;
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    std::string s = std::to_string(i);
    if (s.length() < 3) continue;
    std::sort(std::begin(s), std::end(s));
    if (s[0] != '3' || s[s.length() - 1] != '7') continue;
    bool three = false;
    bool five = false;
    bool seven = false;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == '3')
        three = true;
      else if (s[j] == '5')
        five = true;
      else if (s[j] == '7')
        seven = true;
      else
        break;
    }
    if (three && five && seven) ans++;
  }
  std::cout << ans << std::endl;
  return 0;
}
