#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

long long n;

int f(long long x, int m) {
    if (x > n) return 0;
    return f(x * 10 + 3, m | 1 << 0) + f(x * 10 + 5, m | 1 << 1) + f(x * 10 + 7, m | 1 << 2) + (m == 7);
}

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