#include <bits/stdc++.h>
int T;
int Hashtable[10] = {0};
bool check(long long x) {
  memset(Hashtable, 0, sizeof(Hashtable));
  int num = 0;
  do {
    Hashtable[x % 10]++;
    num++;
    x /= 10;
  } while (x);
  if (Hashtable[7] != 0 && Hashtable[5] != 0 && Hashtable[3] != 0) {
    if (Hashtable[7] + Hashtable[5] + Hashtable[3] == num) return true;
  }
  return false;
}
int main() {
  long long T;
  int sum = 0;
  scanf("%lld", &T);
  for (long long i = 1; i <= T; i++) {
    if (check(i)) {
      sum++;
    }
  }
  printf("%d", sum);
  return 0;
}
