#include <bits/stdc++.h>
using namespace std;
bool check(int n) {
  bool shitigosan = true;
  bool seven = false;
  bool five = false;
  bool three = false;
  while (n > 0) {
    if (n % 10 == 3) {
      three = true;
    } else if (n % 10 == 5) {
      five = true;
    } else if (n % 10 == 7) {
      seven = true;
    } else {
      shitigosan = false;
    }
    n /= 10;
    if (!shitigosan) break;
  }
  if (shitigosan and seven and five and three)
    return true;
  else
    return false;
}
int main() {
  long long int N;
  cin >> N;
  long long int ans = 0;
  if (N < 357) {
    cout << 0 << endl;
  } else {
    for (int i = 357; i <= N; i++) {
      if (check(i))
        ans++;
      else
        continue;
    }
  }
  cout << ans << endl;
}
