#include<bits/stdc++.h>
using namespace std;

long long ans,n;
void fun(long long x, int san,int wu,int qi)
{
	if(x>n)
		return;

	if(san && wu && qi)
		ans++;
	fun(x*10+3, 1,wu,qi);
	fun(x*10+5, san,1,qi);
	fun(x*10+7, san,wu,1);

}
int main()
{
	ans=0;
	int i,j,k,l,m;
	cin>>n;
	fun(0,0,0,0);
	cout<<ans;

	return 0;
}