#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
#define  LL long long

LL n,ans=0;
void dfs(LL x,int a,int b,int c)
{
	if(x>n) return;
	if(a+b+c==3) ans++;
	dfs(x*10+3,1,b,c);
	dfs(x*10+7,a,1,c);
	dfs(x*10+5,a,b,1);
}


int main()
{
	scanf("%lld",&n);
	dfs(0,0,0,0);
	printf("%lld\n",ans);


	return 0;
}

