#include<stdio.h>
int N;int cnt=0;
void dfs(long long num,unsigned char flag357);
int main(){
	scanf("%d",&N);
	dfs(0,0);
	printf("%d\n",cnt);
	return 0;
}

void dfs(long long num,unsigned char flag357){
	if(num<=N){
		if(flag357==07)
			cnt++;
		dfs(num*10+3,flag357|01);
		dfs(num*10+5,flag357|02);
		dfs(num*10+7,flag357|04);
	}
}