#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2147483647;
const long long INFLL = 9223372036854775807LL;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);
struct mint {
  long long value;
  mint(long long value = 0) : value((value % MOD + MOD) % MOD) {}
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint pow(mint m) const { return pow(m.value); }
  mint inv() const {
    long long a = value, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    u %= MOD;
    return u;
  }
  mint &operator+=(const mint a) {
    if ((value += a.value) >= MOD) value -= MOD;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((value += MOD - a.value) >= MOD) value -= MOD;
    return *this;
  }
  mint &operator*=(const mint a) {
    (value *= a.value) %= MOD;
    return *this;
  }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
vector<long long> numbers_753;
long long dfs(long long curr, long long digit) {
  if (digit == 0) return curr;
  numbers_753.push_back(dfs(curr * 10 + 3, digit - 1));
  numbers_753.push_back(dfs(curr * 10 + 5, digit - 1));
  numbers_753.push_back(dfs(curr * 10 + 7, digit - 1));
}
int main() {
  for (int i = (3); i < (10); i++) {
    dfs(0, i);
  }
  vector<long long> range_filtered;
  copy_if((numbers_753).begin(), (numbers_753).end(),
          back_inserter(range_filtered),
          [&](long long x) { return (100 < x && x < 1e9); });
  auto is_contain = [&](string &s, char c) {
    return find((s).begin(), (s).end(), c) != s.end();
  };
  auto filter_753 = [&](long long x) {
    string s = to_string(x);
    return is_contain(s, '3') && is_contain(s, '5') && is_contain(s, '7');
  };
  vector<long long> filtered;
  copy_if((range_filtered).begin(), (range_filtered).end(),
          back_inserter(filtered), [&](long long x) { return filter_753(x); });
  sort((filtered).begin(), (filtered).end());
  long long n;
  cin >> n;
  auto iter = upper_bound((filtered).begin(), (filtered).end(), n);
  int ans = iter - filtered.begin();
  cout << ans << endl;
}
