#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
ll n;
ll ans=0;
void bfs(ll zhi,ll r,bool a,bool b,bool c){
	if(zhi>n)
	return;
	if(a&b&c)
	ans++;
	bfs(zhi+3*r,10*r,true,b,c);
	bfs(zhi+5*r,10*r,a,true,c);
	bfs(zhi+7*r,10*r,a,b,true);
}
int main(){
	cin>>n;
	bfs(0,1,false,false,false);
	printf("%d",ans);
}