#include <bits/stdc++.h>
int loop(int);
int keta;
int aa[11];
int main() {
  int N, i, j, a, b, c, count, x3, x5, x7, x, y, z;
  for (j = 0; j <= 10; j++) {
    aa[j] = 0;
  }
  count = 0;
  keta = 9;
  x3 = 0;
  x5 = 0;
  x7 = 0;
  scanf("%d", &N);
  a = 0;
  while (a <= N) {
    a = 0;
    loop(0);
    ;
    for (i = 0; i <= 10; i++) {
      if ((i == 9) && (aa[i] != 0)) {
        aa[i] = 1;
      }
      a = a + (aa[i] * pow(10, i));
    }
    for (i = 0; i <= 10; i++) {
      if (aa[i] == 3) {
        x3 = 1;
      }
      if (aa[i] == 5) {
        x5 = 1;
      }
      if (aa[i] == 7) {
        x7 = 1;
      }
    }
    if ((x3 == 1) && (x5 == 1) && (x7 == 1)) {
      count++;
      printf("%d \n", a);
    }
    x3 = 0;
    x5 = 0;
    x7 = 0;
  }
  printf("%d \n", count);
  return (0);
}
int loop(int w) {
  switch (aa[w]) {
    case 0:
      aa[w] = 3;
      break;
    case 3:
      aa[w] = 5;
      break;
    case 5:
      aa[w] = 7;
      break;
    case 7:
      aa[w] = 3;
      loop(w + 1);
      break;
    default:
      break;
  }
  return (0);
}
