#include <bits/stdc++.h>
int main() {
  int N;
  scanf("%d", &N);
  int counter = 0;
  int M;
  int a;
  for (int i = 100; i <= N; i++) {
    M = i;
    int digi = (int)log10(M);
    int c = 1;
    int check3 = 0;
    int check5 = 0;
    int check7 = 0;
    for (int j = digi; j >= 0; j--) {
      a = M / pow(10, j);
      if (a == 3) {
        check3 = 1;
      } else if (a == 5) {
        check5 = 1;
      } else if (a == 7) {
        check7 = 1;
      } else {
        c *= 0;
      }
      M = M % (int)(pow(10, j));
    }
    c = check3 * check5 * check7 * c;
    if (c == 1) {
      counter++;
      printf("%d\n", i);
    }
  }
  printf("%d\n", counter);
  return 0;
}
