#include <bits/stdc++.h>
bool solve(int n) {
  int a = 0, b = 0, c = 0;
  while (n) {
    int temp = n % 10;
    if (temp == 3 || temp == 5 || temp == 7) {
      n /= 10;
      if (temp == 3) a++;
      if (temp == 5) b++;
      if (temp == 7) c++;
    } else {
      return false;
    }
  }
  if (a && b && c) {
    return true;
  } else {
    return false;
  }
}
int main() {
  int t;
  scanf("%d", &t);
  if (t <= 356) {
    printf("0\n");
    return 0;
  }
  int res = 0;
  for (int i = 357; i <= t; i += 2) {
    if (solve(i)) {
      res++;
    }
  }
  printf("%d\n", res);
  return 0;
}
