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

int n, cnt;

void dfs(ll x, int f) {
    if(x > n) return;
    if(f == 7) cnt++;
    dfs(x * 10 + 3, f | 1);
    dfs(x * 10 + 5, f | 2);
    dfs(x * 10 + 7, f | 4);
}

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