#include <iostream>
using namespace std;
typedef long long ll;

int N, ans=0;

void dfs(ll cur, int mask) {
    if (cur > N) return;
    if (mask == 7) ans++;
    dfs(cur * 10 + 7, mask | 4);
    dfs(cur * 10 + 5, mask | 2);
    dfs(cur * 10 + 3, mask | 1);    
}

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