#include <bits/stdc++.h>
int main() {
  int time;
  scanf("%d", &time);
  int result = 0;
  if (time < 357) {
    printf("0\n");
  }
  int key3 = 0, key7 = 0, key5 = 0;
  for (int i = 357; i <= time; i++) {
    int temp = i;
    int number;
    while (temp > 0) {
      number = temp % 10;
      if (number != 3 && number != 5 && number != 7) {
        break;
      }
      if (number == 3) {
        key3++;
      }
      if (number == 5) {
        key5++;
      }
      if (number == 7) {
        key7++;
      }
      temp /= 10;
    }
    if (temp == 0 && key3 > 0 && key5 > 0 && key7 > 0) {
      result++;
    }
    key3 = 0;
    key5 = 0;
    key7 = 0;
  }
  printf("%d\n", result);
  return 0;
}
