#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long now = i;
    bool ch7, ch5, ch3;
    ch7 = ch5 = ch3 = false;
    while (now != 0) {
      long long ne = now % 10;
      if (ne == 7) {
        ch7 = true;
      } else if (ne == 5) {
        ch5 = true;
      } else if (ne == 3) {
        ch3 = true;
      } else {
        break;
      }
      now /= 10;
    }
    if (ch7 && ch5 && ch3) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}
