#include <iostream>
#include <map>
#include <vector>
#define int long long
typedef long long ll;
using namespace std;

ll N, count=0;

void check(ll num){
    map<ll, ll> M;
    if(num < N){
        while(num>=1){
            M[num%10]++;
            num = num/10;
        }
        if(M[3]>0&&M[5]>0&&M[7]>0) count++;
    }
}

void dfs(ll num){
    if(num>10000000000) return;
    check(num);
    dfs(10*num+3);
    dfs(10*num+5);
    dfs(10*num+7);
}

signed main(){
    cin >> N;
    dfs(0);
    cout << count << endl;
    return 0;
}