#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
  int n;
  scanf("%d", &n);
  int ans = 0, s, f, t, z, temp, x = 0;
  for (int l = 1; l <= n; l++) {
    temp = l;
    s = 0;
    f = 0;
    t = 0;
    z = 0;
    while (temp > 0) {
      if (temp % 10 == 7)
        s++;
      else if (temp % 10 == 5)
        f++;
      else if (temp % 10 == 3)
        t++;
      else {
        z++;
        break;
      }
      temp /= 10;
    }
    if (s * t * f > 0 && z == 0) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
