#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
std::vector<int64_t> sftnum;
void bfs(int64_t n, bool seven, bool five, bool three) {
  if (n < std::pow(10, 9)) {
    bfs(n * 10 + 3, seven, five, true);
    bfs(n * 10 + 5, seven, true, three);
    bfs(n * 10 + 7, true, five, three);
  } else
    return;
  if (seven && five && three) {
    sftnum.push_back(n);
  }
  return;
}
int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int64_t n;
  cin >> n;
  bfs(0, false, false, false);
  std::sort(sftnum.begin(), sftnum.end());
  auto itr = std::lower_bound(sftnum.begin(), sftnum.end(), n);
  cout << std::distance(sftnum.begin(), itr) << endl;
  return 0;
}
