#include<bits/stdc++.h>
using namespace std;
#define int long long
int N;
int Ans=0;
void dfs(int num,int a,int b,int c)
{
	if(num>N) return;
	if(a&&b&&c) ++Ans;
	dfs(num*10+3,1,b,c);
	dfs(num*10+5,a,1,c);
	dfs(num*10+7,a,b,1);
	return;
}
signed main()
{
	cin>>N;
	dfs(0,0,0,0);
	cout<<Ans<<endl;
	return 0;
}