#include<iostream>
using namespace std;
int n,ans;
void dfs(long long x,int a,int b,int 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("%d",&n);
    dfs(0,0,0,0);
    printf("%d\n",ans);


}
