#include <bits/stdc++.h>
using ll = long long int;
int INF = 1e9+7;
int N;
bool check(int n) {
    string s = to_string(n);
    return (s.find('3') != string::npos &&
            s.find('5') != string::npos &&
            s.find('7') != string::npos);
}
int dfs(int n) {
    if (n > N) return 0;
    int res = 0;
    if (check(n)) res = 1;

    res += dfs(n*10 + 3);
    res += dfs(n*10 + 5);
    res += dfs(n*10 + 7);
    return res;
}

int main() {
    cin >> N;
    cout << dfs(0) << endl;
}
