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

using ll = long long;
ll n, ans;

void dfs(ll a, ll b, ll c, ll x) {
    if (x > n) return;
    if (a && b && c) ans++;

    dfs(1, b, c, x * 10 + 3);
    dfs(a, 1, c, x * 10 + 5);
    dfs(a, b, 1, x * 10 + 7);
}


int main() {
    cin >> n;

    dfs(0, 0, 0, 0);
    cout << ans << endl;

    return 0;
}