#include <bits/stdc++.h>
using namespace std;
int order(int N) {
  int ret = 0;
  while (N != 0) {
    ++ret;
    N /= 10;
  }
  return ret;
}
int main() {
  int N;
  cin >> N;
  int o_N = order(N);
  if (o_N < 3) cout << 0 << endl;
  vector<vector<string> > no753(10);
  no753[2] = {"357", "375", "537", "573", "735", "753"};
  string temp_str;
  for (size_t i = 3; i < o_N; i++) {
    for (auto str : no753[i - 1]) {
      for (size_t j = 0; j < i + 1; j++) {
        temp_str = str;
        no753[i].push_back(temp_str.insert(j, "3"));
        temp_str = str;
        no753[i].push_back(temp_str.insert(j, "5"));
        temp_str = str;
        no753[i].push_back(temp_str.insert(j, "7"));
      }
    }
    sort(no753[i].begin(), no753[i].end());
    no753[i].erase(unique(no753[i].begin(), no753[i].end()), no753[i].end());
  }
  vector<int> sorted_753;
  for (auto vec : no753) {
    for (auto no : vec) {
      sorted_753.push_back(stoi(no));
    }
  }
  auto itr_upper = upper_bound(sorted_753.begin(), sorted_753.end(), N);
  cout << itr_upper - sorted_753.begin() << endl;
  return 0;
}
