#include<cstdio>
#include<vector>


using ll=long long;

int calc(int n, int f, ll v)
{
	int ret=0;

	if(v>n) return 0;
	if(f==7) ret++;
	ret+=calc(n, f|1, v*10+7);
	ret+=calc(n, f|2, v*10+5);
	ret+=calc(n, f|4, v*10+3);
	return ret;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		printf("%d\n", calc(n, 0, 0));
	}

	return 0;
}
