import std.stdio;
import std.algorithm;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto N = to!ulong(tokens[0]);

	ulong tmp = N;
	ulong digit;
	while (tmp != 0)
	{
		tmp /= 10;
		++digit;
	}
	
	ulong f(ulong flag, ulong digit_r, ulong x, bool zero = false)
	{
		if (flag == 0b111) return pow(3, digit_r);
		if (digit_r == 0) return 0;

		ulong top    = x / pow(10, digit_r - 1);
		ulong topCnt = top >= 7 ? 3 : top >= 5 ? 2 : top >= 3 ? 1 : 0;
		bool just    = top == 7 || top == 5 || top == 3;
		ulong newX   = x - top * pow(10, digit_r - 1);
		ulong result;
		if (zero) result += f(flag, digit_r - 1, pow(10, digit_r - 1) - 1, true);
		foreach (i; 0..topCnt)
		{
			if (just && i == topCnt - 1)
				result += f(flag | (1 << i), digit_r - 1, newX);
			else
				result += f(flag | (1 << i), digit_r - 1, pow(10, digit_r - 1) - 1);
		}
		return result;
	}

	ulong result = f(0, digit, N, true);
	

	writeln(result);
	stdout.flush();
/*}catch (Throwable e)
	{
		writeln(e.toString());
	}
readln();*/
}