#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
LL check(LL n)
{
	LL x3,x5,x7;
	x3=x5=x7=0;
	while(n)
	{
		if(n%10==3)
			x3++;
		if(n%10==5)
			x5++;
		if(n%10==7)
			x7++;
		n/=10;
	}
	return x3&&x5&&x7;
}
LL solve3(LL n)
{
	LL ans,sum;
	ans=0;
	for(LL i=3;i<=7;i+=2)
		for(LL j=3;j<=7;j+=2)
			for(LL k=3;k<=7;k+=2)
			{
				sum=i*100+j*10+k;
				if(sum<=n && check(sum))
				{
						ans++;
						//printf("%d\n",sum);
				}

			}
		return ans;
}
LL solve4(LL n)
{
	LL ans,sum;
	ans=0;
	for(LL i=3;i<=7;i+=2)
		for(LL j=3;j<=7;j+=2)
			for(LL k=3;k<=7;k+=2)
				for(LL y=3;y<=7;y+=2)
				{
					sum=i*1000+j*100+k*10+y;
					if(sum<=n && check(sum))
					{
						ans++;
					//	printf("%d\n",sum);
					}
				}
		return ans;
}
LL solve5(LL n)
{
	LL ans,sum;
	ans=0;
	for(LL i=3;i<=7;i+=2)
		for(LL j=3;j<=7;j+=2)
			for(LL k=3;k<=7;k+=2)
				for(LL y=3;y<=7;y+=2)
					for(LL x=3;x<=7;x+=2)
					{
						sum=i*10000+j*1000+k*100+y*10+x;
						if(sum<=n && check(sum))
							ans++;
					}
		return ans;
}
LL solve6(LL n)
{
	LL ans,sum;
	ans=0;
	for(LL i=3;i<=7;i+=2)
		for(LL j=3;j<=7;j+=2)
			for(LL k=3;k<=7;k+=2)
				for(LL y=3;y<=7;y+=2)
					for(LL x=3;x<=7;x+=2)
						for(LL d=3;d<=7;d+=2)
						{
							sum=i*100000+j*10000+k*1000+y*100+x*10+d;
							if(sum<=n && check(sum))
								ans++;
						}
		return ans;
}
LL solve7(LL n)
{
	LL ans,sum;
	ans=0;
	for(LL i=3;i<=7;i+=2)
		for(LL j=3;j<=7;j+=2)
			for(LL k=3;k<=7;k+=2)
				for(LL y=3;y<=7;y+=2)
					for(LL x=3;x<=7;x+=2)
						for(LL d=3;d<=7;d+=2)
							for(LL c=3;c<=7;c+=2)
							{
								sum=i*1000000+j*100000+k*10000+y*1000+x*100+d*10+c;
								if(sum<=n && check(sum))
									ans++;
							}
		return ans;
}
LL solve8(LL n)
{
	LL ans,sum;
	ans=0;
	for(LL i=3;i<=7;i+=2)
		for(LL j=3;j<=7;j+=2)
			for(LL k=3;k<=7;k+=2)
				for(LL y=3;y<=7;y+=2)
					for(LL x=3;x<=7;x+=2)
						for(LL d=3;d<=7;d+=2)
							for(LL c=3;c<=7;c+=2)
								for(LL r=3;r<=7;r+=2)
								{
									sum=i*10000000+j*1000000+k*100000+y*10000+x*1000+d*100+c*10+r;
									if(sum<=n && check(sum))
										ans++;
								}
		return ans;
}
LL solve9(LL n)
{
	LL ans,sum;
	ans=0;
	for(LL i=3;i<=7;i+=2)
		for(LL j=3;j<=7;j+=2)
			for(LL k=3;k<=7;k+=2)
				for(LL y=3;y<=7;y+=2)
					for(LL x=3;x<=7;x+=2)
						for(LL d=3;d<=7;d+=2)
							for(LL c=3;c<=7;c+=2)
								for(LL r=3;r<=7;r+=2)
									for(LL g=3;g<=7;g+=2)
								{
									sum=i*100000000+j*10000000+k*1000000+y*100000+x*10000+d*1000+c*100+r*10+g;
									if(sum<=n && check(sum))
										ans++;
								}
		return ans;
}
int main()
{
	LL n,s=0;
	scanf("%lld",&n);
	LL t=n;
	while(t)
	{
		s++;
		t/=10;
	}
	switch(s)
	{
		case 1:
		case 2:
		case 3: printf("%lld\n",solve3(n));break;
		case 4: printf("%lld\n",solve4(n)+solve3(n));break;
		case 5: printf("%lld\n",solve5(n)+solve4(n)+solve3(n));break;
		case 6: printf("%lld\n",solve6(n)+solve5(n)+solve4(n)+solve3(n));break;
		case 7: printf("%lld\n",solve7(n)+solve6(n)+solve5(n)+solve4(n)+solve3(n));break;
		case 8: printf("%lld\n",solve8(n)+solve7(n)+solve6(n)+solve5(n)+solve4(n)+solve3(n));break;
		case 9: printf("%lld\n",solve9(n)+solve8(n)+solve7(n)+solve6(n)+solve5(n)+solve4(n)+solve3(n));break;
	}
    return 0;
}


Measured memory_bytes: 256