#include<iostream>
#include<string.h>
using namespace std;
int N,count=0;

void getNum(long long num,int flag){
	int baiwei = flag/100;
	int shiwei = flag/10%10;
	int gewei = flag%10;
	if(num<N){
		if(baiwei&&shiwei&&gewei){
			count++;
		}
		int temp1=flag,temp2=flag,temp3=flag;
		if(baiwei==0){
			temp1+=100;
		}
		getNum(num*10+3,temp1);
		if(shiwei==0){
			temp2+=10;
		}
		getNum(num*10+5,temp2);
		if(gewei==0){
			temp3+=1;
		}
		getNum(num*10+7,temp3);
	}
}

int main(){
	scanf("%d",&N);
	getNum(0,0);
	printf("%d\n",count);
}