#include<iostream>
using namespace std;
int n, ans = 0;
void solve(long num, bool s, bool t, bool r) {
    if (num > n) return;
    if (s && t && r) ans++;
    solve(num * 10 + 7, true, t, r);
    solve(num * 10 + 5, s, true, r);
    solve(num * 10 + 3, s, t, true);
}
int main() {
    cin >> n;
    solve(0, false, false, false);
    cout << ans << endl;
}
