#include<cmath>
#include <iostream>
using namespace std;

uint64_t C[11][11] = {};

uint64_t pow_s(int x, int a)
{
	uint64_t res = 1;

	if (a > 0)
	{
		for (int i = 1; i <= a; i++)
		{
			res = res * x;
		}
	}
	return(res);
}

uint64_t combination(unsigned int n, unsigned int r) {
	if (C[n][r] == 0)
	{
		if (r * 2 > n) r = n - r;
		uint64_t dividend = 1;
		uint64_t divisor = 1;
		for (unsigned int i = 1; i <= r; ++i) {
			dividend *= (n - i + 1);
			divisor *= i;
		}
		C[n][r] = dividend / divisor;
	}
	return C[n][r];
}

uint64_t calc_2digit_count(int fig)
{
	// 桁数=figの数に対して2つの数による組み合わせ数を計算
	uint64_t calc2 = 0;

	for (int i = 1; i < fig; i++)
	{
		calc2 += combination(fig, i);
	}
	return calc2;
}

uint64_t calc_3digit_count(int fig)
{
	// 桁数=figの数に対して3つの数による組み合わせ数を計算
	uint64_t calc3 = 0;

	for (int i = 1; i < fig; i++)
	{
		for (int j = 1; j < fig - i; j++)
		{
			calc3 += combination(fig, i) *combination(fig - i, j);
		}
	}
	return calc3;
}

uint64_t GetMax753Number(uint64_t orig)
{
	int fig; // 桁数
	uint64_t ret = 0;
	uint64_t tmp = 0;
	int of = 0;

	fig = (int)log10((double)orig) + 1;

	for (int i = fig; i > 0; i--)
	{
		int tg = 0;
		if (of == 1)
		{
			tg = 7;
		}
		else
		{
			tg = (int)(orig / pow_s(10, i - 1)) % 10;
		}

		switch (tg)
		{
		case 0:
		case 1:
		case 2:
			tg = 0;
			of = 1;
			break;
		case 4:
			tg = 3;
			of = 1;
			break;
		case 6:
			tg = 5;
			of = 1;
			break;
		case 8:
		case 9:
			tg = 7;
			of = 1;
		}

		tmp = tmp * 10 + tg;
	}
	//	cout << tmp << endl;

	fig = (int)log10((double)tmp) + 1;
	for (int i = 1; i <= fig; i++)
	{
		int tg = (int)(tmp / pow_s(10, i - 1)) % 10;

		if ((tg == 0) && (i != fig))
		{
			int tg2 = (int)(tmp / pow_s(10, i)) % 10; //  1つ上の桁
			tg = 7;
			if (tg2 == 3)
			{
				tmp -= 3 * pow_s(10, i);
			}
			else if (tg2 > 3)
			{
				tmp -= 2 * pow_s(10, i);
			}
		}

		ret = ret + tg * pow_s(10, i - 1);
	}

	//	cout << ret << endl << endl;

	return(ret);
}

uint64_t Count753Num(uint64_t N, int fig, int f753, int oflg)
{
	uint64_t ret = 0;
	int tg;

	if (oflg == 1)
	{
		tg = 7;
	}
	else
	{
		tg = (int)(N / pow_s(10, fig - 1)) % 10;
	}

	for (int i = tg; i >= 3; i = i - 2)
	{
		int f753t = f753 | (int)pow_s(2, ((i - 1) / 2) - 1);
		if (fig == 1)
		{
			if (f753t == 7) ret++;
		}
		else
		{
			if (i < tg)
			{
				oflg = 1;
			}
			ret += Count753Num(N, fig - 1, f753t, oflg);
		}
	}

	return(ret);
}


int main()
{
	uint64_t N; // 入力された数
	int fig; // 桁数
	int figN753; // 桁数
	int f753 = 0; // 753の使用フラグ
	int tg;
	uint64_t N753; // Nを超えない753のいずれかで構築された数
	uint64_t Count753[11] = {};
	uint64_t Total753 = 0;

	cin >> N;

	fig = (int)log10((double)N) + 1;
	//	cout << fig << endl;

		// 桁数-1までの753数の算出
	for (int i = 1; i < fig; i++)
	{
		Count753[i] = calc_3digit_count(i);
		Total753 += Count753[i];
		//		cout << i << " " << Count753[i] << endl;
	}

	// 最上位の桁数で場合分け
	tg = (int)(N / pow_s(10, fig - 1));
	switch (tg)
	{
	case 1:
	case 2: // 1桁少ないの753数が対象
		break;
	case 4: // 3で始まる753数を追加
		Total753 += calc_3digit_count(fig) / 3;
		break;
	case 6: // 3と5で始まる753数を追加
		Total753 += calc_3digit_count(fig) * 2 / 3;
		break;
	case 8: // 当該桁数の753数を追加
	case 9:
		Total753 += calc_3digit_count(fig);
		break;

	case 3:
	case 5:
	case 7:
		N753 = GetMax753Number(N);
		figN753 = (int)log10((double)N753) + 1;
		Total753 += Count753Num(N753, figN753, f753, 0);
		break;
	}

	cout << Total753 << endl;
	return(0);

}


Measured memory_bytes: 512