#include <stdio.h>

int n, c = 0;

void dfs(int x, int f3, int f5, int f7, int l)
{
	if(x > n) return;
	if(f3 && f5 && f7) c++;
	if(l == 9) return;
	
	int t = 10 * x, tl = l + 1;
	dfs(t + 3, 1, f5, f7, tl);
	dfs(t + 5, f3, 1, f7, tl);
	dfs(t + 7, f3, f5, 1, tl);
}

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