#include <bits/stdc++.h>
void rec(int i, std::vector<long long>& c) {
  std::string s = std::to_string(i);
  if (s.length() >= 10) return;
  std::sort(std::begin(s), std::end(s));
  s.erase(std::unique(std::begin(s), std::end(s)), std::end(s));
  if (s == "357") {
    c.push_back(i);
    rec(i * 10 + 3, c);
    rec(i * 10 + 5, c);
    rec(i * 10 + 7, c);
  }
}
int main() {
  long long N;
  std::cin >> N;
  std::vector<long long> c;
  for (int i = 357; i <= 753; i++) {
    rec(i, c);
  }
  std::sort(std::begin(c), std::end(c));
  long long ans = 0;
  for (int i = 0; i < c.size(); i++) {
    if (c[i] <= N)
      ans++;
    else
      break;
  }
  std::cout << ans << std::endl;
  return 0;
}
