#include <bits/stdc++.h>
int check(int n);
int main(void) {
  int i, n, kotae = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    kotae += check(i);
  }
  printf("%d", kotae);
  return 0;
}
int check(int n) {
  int a = 0, b = 0, c = 0, d = 1;
  for (; n > 0; n = n / 10) {
    switch (n % 10) {
      case 3:
        a++;
        break;
      case 5:
        b++;
        break;
      case 7:
        c++;
        break;
      default:
        d = 0;
        break;
    }
  }
  if (a * b * c * d == 0) {
    return 0;
  } else {
    return 1;
  }
}
