#include <bits/stdc++.h>
int count_753(long s, long N, long ans, int a, int b, int c) {
  long tmp = ans;
  if (s > N) return tmp;
  if (a + b + c == 3) tmp++;
  count_753((s * 10 + 3), N, tmp, 1, b, c);
  count_753((s * 10 + 5), N, tmp, a, 1, c);
  count_753((s * 10 + 7), N, tmp, a, b, 1);
}
int main(void) {
  long N;
  scanf("%ld", &N);
  long ans = 0;
  ans = count_753(0, N, ans, 0, 0, 0);
  printf("%ld\n", ans);
  return 0;
}
