#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int thr = 0, fiv = 0, sev = 0;
    for (int j = 0; j < log10(i) + 1; j++) {
      if (i % 10 == 3) {
        thr++;
        i /= 10;
      } else if (i % 10 == 5) {
        fiv++;
        i /= 10;
      } else if (i % 10 == 7) {
        sev++;
        i /= 10;
      } else {
        thr = 0;
        fiv = 0;
        sev = 0;
        break;
      }
    }
    if (thr >= 1 && fiv >= 1 && sev >= 1) ans++;
  }
  cout << ans << endl;
}
