#include <bits/stdc++.h>
int main(void) {
  int a;
  scanf("%d", &a);
  int count = 0;
  char c[20];
  for (int i = 357; i < a + 1; i++) {
    snprintf(c, 20, "%d", i);
    int it;
    it = strlen(c);
    for (int j = 0; j < it; j++) {
      if (c[j] != '7' && c[j] != '5' && c[j] != '3') {
        break;
      }
      int flaga = 1;
      int flagb = 1;
      int flagc = 1;
      for (int j = 0; j < it; j++) {
        if (c[j] == '7') {
          flaga = 0;
        }
        if (c[j] == '5') {
          flagb = 0;
        }
        if (c[j] == '3') {
          flagc = 0;
        }
      }
      if (j == it - 1 && flaga == 0 && flagb == 0 && flagc == 0) {
        count++;
      }
    }
  }
  printf("%d", count);
  return 0;
}
