#include<cstdio>
int n,count=0;
void dfs(long long nextnum,unsigned char flag357)
{
	if(nextnum<=n)
	{
		if(flag357==7)//7的二进制位是111
			count++;
		dfs(nextnum*10+3,flag357|1);//1的二进制位001
		dfs(nextnum*10+5,flag357|2);//2的二进制位010
		dfs(nextnum*10+7,flag357|4);//4的二进制位100
	}
}
int main()
{
	scanf("%d",&n);
	dfs(0,0);
	printf("%d\n",count);
	return 0;
}
