#include <bits/stdc++.h>
using namespace std;
long long n;
char c[3] = {'3', '5', '7'};
void solve() {
  vector<string> v;
  v.push_back("375");
  int pos = 0;
  while (true) {
    int end = v.size();
    if (v[end - 1].size() >= to_string(n).size()) {
      break;
    }
    for (int i = pos; i < end; i++) {
      for (int j = 0; j < 3; j++) {
        v.push_back(v[i] + c[j]);
      }
    }
    pos = end;
  }
  set<string> s;
  for (int i = 0; i < v.size(); i++) {
    sort(v[i].begin(), v[i].end());
    s.insert(v[i]);
  }
  set<long long> s2;
  for (string str : s) {
    do {
      s2.insert(stoll(str));
    } while (std::next_permutation(str.begin(), str.end()));
  }
  auto iter = s2.lower_bound(n);
  if (*iter > n) {
    cout << distance(s2.begin(), iter) << endl;
  } else {
    cout << distance(s2.begin(), iter) + 1 << endl;
  }
}
int main() {
  cin >> n;
  solve();
}
