#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, mi, fl;
  int tc = 0;
  int fc = 0;
  int sc = 0;
  int co = 0;
  cin >> n;
  if (n < 357) {
    cout << 0 << endl;
  } else {
    for (i = 357; i <= n; i += 2) {
      tc = 0;
      fc = 0;
      sc = 0;
      mi = i;
      fl = 0;
      while (mi) {
        if (mi % 10 == 3) {
          tc++;
        } else if (mi % 10 == 5) {
          fc++;
        } else if (mi % 10 == 7) {
          sc++;
        } else {
          fl = 1;
          break;
        }
        mi /= 10;
      }
      if ((tc != 0) && (fc != 0) && (sc != 0) && (fl == 0)) {
        co++;
      }
    }
    cout << co << endl;
  }
}
