#include<cstdio>

long n;
long ans=0;
void dfs(long x,long a,long b,long c){
    if(x>n) return;
    if(a&&b&&c) ans++;
    dfs(10*x+3,a+1,b,c);
    dfs(10*x+5,a,b+1,c);
    dfs(10*x+7,a,b,c+1);
}
int main(){
    scanf("%ld",&n);
    dfs(0,0,0,0);
    printf("%ld",ans);
    return 0;
}
