#include<cstdio>
using namespace std;
int biao[1005]={0,732,732,732,1334,1334,1936,1936,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,2538,3140,3140,3805,3805,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,4470,5135,5135,5737,5737,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,6402,7067,7067,7732,7732,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8334,8936,8936,9601,9601,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10266,10931,10931,11596,11596,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12325,12990,12990,13719,13719,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,14384,15049,15049,15714,15714,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,16443,17108,17108,17710,17710,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,18375,19104,19104,19769,19769,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,20434,21099,21099,21828,21828,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,22493,23222,23222,23887,23887,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,24552,25217,25217,25882,25882,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484,26484};
int main()
{
	int n;scanf("%d",&n);int ans=0;
	ans=biao[n/1000000];
	for(int i=n/1000000*1000000+1;i<=n;++i) {
		bool f3=false,f5=false,f7=false,f0=false;
		int now=i;
		while(now) {if(now%10==3) f3=true;else if(now%10==5) f5=true;else if(now%10==7) f7=true;else f0=true;now/=10;}
		if(f3&&f5&&f7&&!f0) ++ans;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128