#include<stdio.h>
long long n;
int cnt = 0;
void f(long long k, bool r3, bool r5, bool r7)
{
	if (k > n)
		return;
	if (r3&&r5&&r7) cnt++;
	f(k * 10 + 3, true, r5, r7); f(k * 10 + 5, r3, true, r7); f(k * 10 + 7, r3, r5, true);
}

int main()
{
	//n =999999999;
	scanf("%lld", &n);
	f(0, false, false, false);
	printf("%d", cnt);
}