#include<stdio.h>

long long N;
int num;

void DFS(long long nown,unsigned int flag){
	if(nown<=N){
		if(flag==7) num++;
		DFS(nown*10+3,flag|1);
		DFS(nown*10+5,flag|2);
		DFS(nown*10+7,flag|4);
	}
}

int main(){
	while(scanf("%d",&N)==1){
		num=0;
		DFS(0,0);
		printf("%d\n",num);
	}
	return 0;
}