#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using lli = long long int;
ll MM = 1000000000;
ll mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)

ll n; 
ll ans = 0;

void dfs(ll x, ll c3, ll c5, ll c7){
    if(x > n) return;
    if(c3 >= 1 && c5 >= 1 && c7 >= 1) ans++;
    dfs(x*10 + 3, c3 + 1, c5, c7);
    dfs(x*10 + 5, c3, c5 + 1, c7);
    dfs(x*10 + 7, c3, c5, c7 + 1);
}

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