#include <bits/stdc++.h>
long long resolve(const std::string a, long long n) {
  auto val = std::stoll(a);
  int result = 0;
  if (val > n) {
    return result;
  }
  bool g3 = false, g7 = false, g5 = false;
  while (val > 0) {
    long long tmp = val % 10;
    if (tmp == 3) {
      g3 = true;
    } else if (tmp == 7) {
      g7 = true;
    } else if (tmp == 5) {
      g5 = true;
    }
    val /= 10;
  }
  if (g3 && g7 && g5) {
    result++;
  }
  result += resolve(a + "3", n);
  result += resolve(a + "7", n);
  result += resolve(a + "5", n);
  return result;
}
int main() {
  long long N;
  std::cin >> N;
  int find = 0;
  if (N < 357) {
    return find;
  }
  if (N > 777777753) {
    N = 777777753;
  }
  std::cout << resolve("0", N) << std::endl;
  return 0;
}
