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

typedef long long ll;
int N,cnt;

void solve(ll now,bool c3,bool c5,bool c7){
    if(now > N) return;
    if(c3 && c5 && c7) cnt++;
    
    solve(now*10+3,true,c5,c7);
    solve(now*10+5,c3,true,c7);
    solve(now*10+7,c3,c5,true);
}

int main(){
    cin>>N;
    cnt = 0;
    solve(0,false,false,false);
    cout<<cnt<<endl;

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

typedef long long ll;
int N,cnt;

void solve(ll now,bool c3,bool c5,bool c7){
    if(now > N) return;
    if(c3 && c5 && c7) cnt++;
    
    solve(now*10+3,true,c5,c7);
    solve(now*10+5,c3,true,c7);
    solve(now*10+7,c3,c5,true);
}

int main(){
    cin>>N;
    cnt = 0;
    solve(0,false,false,false);
    cout<<cnt<<endl;

    return 0;
}