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

long long ans;
long long n;
void test(long long current, int use){
	if(current > n) return;
	if(use==0b111)ans++;

	test(current*10 +7, use|0b001);
	test(current*10 +5, use|0b010);
	test(current*10 +3, use|0b100);
}

int main(){
	cin>>n;		ans=0;
	test(0,0);

	cout<<ans<<endl;

	return 0;
}
