#include <bits/stdc++.h>
using namespace std;
int n =1e9,c=0;
set<int> st;
int a[3]={3,5,7};
int b[4]={3,3,5,7};
int c[4]={3,5,5,7};
int d[4]={3,5,7,7};
int main(){
	int x;
	cin>>x;
	do{
		st.insert(a[0]*100+a[1]*10+a[2]);
	}while(next_permutation(a,a+3));
	do{
		st.insert(b[0]*1000+b[1]*100+b[2]*10+b[3]);
	}while(next_permutation(a,a+4));
	do{
		st.insert(c[0]*1000+c[1]*100+c[2]*10+c[3]);
	}while(next_permutation(a,a+4));
	do{
		st.insert(d[0]*1000+d[1]*100+d[2]*10+d[3]);
	}while(next_permutation(a,a+4));
	for(set<int>::iterator it=st.begin();it!=st.end();it++){
		if(*it<x) c++;
	}	
	printf("%d",c);
	return 0;
}