#include <cstdio>
long long  N;
int count = 0;
void dfs(long long t,unsigned char k){
	if(t<=N){
		if(k == 7){
			count++;
		}
		dfs(t*10+3,k|1);
		dfs(t*10+5,k|2);
		dfs(t*10+7,k|4);
	}
}
int main(){
	//freopen("_intimesoftrain.txt","r",stdin);
	scanf("%lld",&N);
	dfs(0,0);
	printf("%d",count);
	return 0;
}