#include <bits/stdc++.h>
int main(void) {
  int num;
  int order[11] = {0};
  int i_order = 3;
  scanf("%ld", &num);
  if (num < 357) {
    printf("0");
    return 0;
  }
  long int i;
  int j;
  int count = 0;
  int flag3 = 0, flag5 = 0, flag7 = 0, missflag;
  order[0] = 6;
  order[1] = 5;
  order[2] = 3;
  for (i = 357; i <= num; i++) {
    flag3 = 0;
    flag5 = 0;
    flag7 = 0;
    missflag = 0;
    order[0]++;
    if (i == 777777754) {
      break;
    }
    if (i == 100000000) i_order == 9;
    if (i == 10000000) i_order == 8;
    if (i == 1000000) i_order == 7;
    if (i == 100000) i_order == 6;
    if (i == 10000) i_order == 5;
    if (i == 1000) i_order == 4;
    for (j = 1; j < 11; j++) {
      if (order[j - 1] == 10) {
        order[j - 1] = 0;
        order[j]++;
      }
    }
    for (j = 0; j < i_order; j++) {
      if (order[j] != 3 && order[j] != 5 && order[j] != 7) {
        missflag++;
        break;
      } else if (order[j] == 3) {
        flag3++;
      } else if (order[j] == 5) {
        flag5++;
      } else if (order[j] == 7) {
        flag7++;
      }
    }
    if (missflag == 0 && flag3 != 0 && flag5 != 0 && flag7 != 0) {
      count++;
    }
  }
  printf("%d", count);
  return 0;
}
