#include <bits/stdc++.h>
using namespace std;
void solve() {
  int N;
  cin >> N;
  set<long long int> Set;
  Set.insert(0);
  for (int i = 0; i < 10; ++i) {
    set<long long int> SetNext;
    set<long long int>::iterator it = Set.begin();
    while (it != Set.end()) {
      long long int num = *it;
      SetNext.insert(num * 10 + 3);
      SetNext.insert(num * 10 + 5);
      SetNext.insert(num * 10 + 7);
      ++it;
    }
    it = SetNext.begin();
    while (it != SetNext.end()) {
      Set.insert(*it);
      ++it;
    }
  }
  set<long long int>::iterator it = Set.begin();
  int ans = 0;
  while (*it < N) {
    long long int num = *it;
    ++it;
    bool isThree = false;
    bool isFive = false;
    bool isSeven = false;
    while (num > 0) {
      if (num % 10 == 3) {
        isThree = true;
      } else if (num % 10 == 5) {
        isFive = true;
      } else if (num % 10 == 7) {
        isSeven = true;
      }
      num /= 10;
    }
    if (isThree && isFive && isSeven) {
      ++ans;
    }
  }
  cout << ans << endl;
}
int main() {
  solve();
  return (0);
}
