#include <bits/stdc++.h>
using namespace std;
int whether753(long x) {
  long num = x;
  long amari = 0;
  int i7 = 0, i5 = 0, i3 = 0;
  while (num > 0) {
    amari = num % 10;
    num /= 10;
    if (amari == 3) {
      i3++;
    } else if (amari == 5) {
      i5++;
    } else if (amari == 7) {
      i7++;
    } else {
      return 0;
    }
  }
  if ((i7 > 0) && (i5 > 0) && (i3 > 0)) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  long N;
  cin >> N;
  int count = 0;
  for (long i = 1; i <= N; i++) {
    if (whether753(i) == 1) {
      count++;
    }
  }
  cout << count << endl;
}
