#include <stdio.h>
int n, m, i, j, k, ans, c[9];
void dfs(long long s){
	int i, j, k;
	if(s > n) return;
	if(c[3]&&c[5]&&c[7]) ans++;
	for(i=3; i<=7; i+=2){
		c[i]++;
		dfs(s*10+i);
		c[i]--;
	}
}
int main(){
	scanf("%d", &n);
	dfs(0);
	printf("%d\n", ans);
	return 0;
}