#include <iostream>

typedef long long ll;

using namespace std;

ll cnt = 0, n;

ll dfs(ll v, bool f3, bool f5, bool f7) {
    if (v > n) return 0;
    return dfs(v * 10 + 3, 1, f5, f7) + dfs(v * 10 + 5, f3, 1, f7) + dfs(v * 10 + 7, f3, f5, 1) + (f3 & f5 & f7);
}

int main() {
    cin >> n;
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}
