#include <bits/stdc++.h>
using namespace std;

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = __INT_MAX__;               // 2^31 - 1
const long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll 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 {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll 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<ll> numbers_753;
void dfs(ll curr, ll digit) {
    if (digit <= 0) {
        numbers_753.push_back(curr);
        return;
    }

    dfs(curr * 10 + 3, digit - 1);
    dfs(curr * 10 + 5, digit - 1);
    dfs(curr * 10 + 7, digit - 1);
}

int main() {
    repeat(i, 3, 10) {
        dfs(0, i);
    }

    // vl range_filtered;
    // copy_if(all(numbers_753), back_inserter(range_filtered),
    //         [&](ll x) { return (100 < x && x < 1e9); });

    auto is_contain = [&](string &s, char c) {
        return find(all(s), c) != s.end();
    };
    auto filter_753 = [&](ll x) {
        string s = to_string(x);
        return is_contain(s, '3') && is_contain(s, '5') && is_contain(s, '7');
    };

    vl filtered;
    copy_if(all(numbers_753), back_inserter(filtered),
            [&](ll x) { return filter_753(x); });
    sort(all(filtered));
    // for_each(all(filtered), [](ll x) { debug(x); });

    ll n;
    cin >> n;
    auto iter = upper_bound(all(filtered), n);
    int ans = iter - filtered.begin();
    out(ans);
}


Measured memory_bytes: 892