#include <bits/stdc++.h>
int find(long n) {
  long m = n;
  while (m) {
    if (m % 10 != 5 && m % 10 != 7 && m % 10 != 3) return 0;
    m / 10;
  }
  return 1;
}
int main() {
  int count = 0;
  long n;
  long i;
  scanf("%ld", &n);
  for (i = 1; i <= n; i++) {
    if (find(i)) count++;
  }
  printf("%d", count);
  return 0;
}
