#include<iostream>
using namespace std;
long long n;
int dfs(long long x,bool A,bool B,bool C){
	if(x>n) return 0;
	long long ret=0;
	if(A&&B&&C) ret++;
	ret+=dfs(x*10+7,true,B,C);
	ret+=dfs(x*10+5,A,true,C);
	ret+=dfs(x*10+3,A,B,true) ;
	return ret;
}
int main()
{
	cin >> n;
	cout << dfs(0,false,false,false)<<endl ;
	return 0;	
}