#include <bits/stdc++.h>
int compare_int(const void *a, const void *b) {
  return *(long int *)b - *(long int *)a;
}
int compare_int_small(const void *a, const void *b) {
  return *(long int *)a - *(long int *)b;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
int main(void) {
  long int n;
  int ans = 0;
  int cnt3 = 0;
  int cnt5 = 0;
  int cnt7 = 0;
  int other = 0;
  scanf("%ld", &n);
  for (long int i = 357; i <= n; i++) {
    long int tmp = i;
    while (tmp > 9) {
      if (tmp % 10 == 3) {
        cnt3++;
      } else if (tmp % 10 == 5) {
        cnt5++;
      } else if (tmp % 10 == 7) {
        cnt7++;
      } else {
        other++;
      }
      tmp = tmp / 10;
    }
    if (tmp == 3) {
      cnt3++;
    } else if (tmp == 5) {
      cnt5++;
    } else if (tmp == 7) {
      cnt7++;
    } else {
      other++;
      ;
    }
    if (cnt3 > 0 && cnt5 > 0 && cnt7 > 0 && other == 0) {
      ans++;
    }
    cnt3 = 0;
    cnt5 = 0;
    cnt7 = 0;
    other = 0;
  }
  printf("%d\n", ans);
  return 0;
}
