#include<cstdio>

#define i64 long long int

int n, ans;

void dfs(i64 cur, int mask) {
	if (cur>n) return;
	if(mask==7) ans++;
	
	dfs(cur*10+3, mask | 1);
	dfs(cur*10+5, mask | 2);
	dfs(cur*10+7, mask | 4);
}

int main() {
	scanf("%d", &n);
	
	ans = 0;
	dfs(0LL, 0);
	printf("%d\n", ans);
	
	return 0;
}