#include <cstdio>
#include <cstdint>

int dfs(intmax_t N, intmax_t i, int b) {
  if (i > N) return 0;
  int res = 0;
  if (b == 7) ++res;
  res += dfs(N, 10*i+7, b|4);
  res += dfs(N, 10*i+5, b|2);
  res += dfs(N, 10*i+3, b|1);
  return res;
}

int main() {
  int N;
  scanf("%d", &N);

  printf("%d\n", dfs(N, 0, 0));
}