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

int n;

int dfs(long long x, int f) {
    if (x > n) return 0;

    int ret = f == 7;
    ret += dfs(10 * x + 3, f | 1);
    ret += dfs(10 * x + 5, f | 2);
    ret += dfs(10 * x + 7, f | 4);

    return ret;
}
int main()
{
    cin >> n;

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

    return 0;
}
