#include <iostream>
using namespace std;
long long n;
long long ans=0;
void dfs(long long x,int a,int b,int c)
{
	if(x>n)
		return;
	if(a&&b&&c)ans++;
	dfs(x*10+3,a+1,b,c);
	dfs(x*10+5,a,b+1,c);
	dfs(x*10+7,a,b,c+1);
}
int main()
{
	cin>>n;
	dfs(0,0,0,0);
	cout<<ans<<endl;
	return 0;
}