#include<bits/stdc++.h>
using namespace std;
int ans,N;
void dfs(long long n,bool a,bool b,bool c){
    if(a&&b&&c&&n<=N)
    ans++;
    if(n>N)
    return;
    dfs(n*10+3,1,b,c);
    dfs(n*10+5,a,1,c);
    dfs(n*10+7,a,b,1);
}

int main(){
    cin>>N;
    ans=0;
    dfs(3,1,0,0);dfs(5,0,1,0);dfs(7,0,0,1);
    cout<<ans<<endl;
    return 0;
}