unittest
{
	assert( [ "575" ].parse.expand.solve == 4 );
	assert( [ "3600" ].parse.expand.solve == 13 );
	assert( [ "999999999" ].parse.expand.solve == 26484 );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	return solve2( n, 0, 0, 0 );
}

long solve2( long m, long n, long d, byte f )
{
	auto dd = 10L ^^ d;
	auto r = 0L;
	
	if( f == 0b111 ) r += 1;
	
	auto n3 = n + 3L * dd;
	if( n3 <= m )
	{
		r += solve2( m, n3, d + 1, f | 0b100 );

		auto n5 = n + 5L * dd;
		if( n5 <= m )
		{
			r += solve2( m, n5, d + 1, f | 0b010 );
		
			auto n7 = n + 7L * dd;
			if( n7 <= m )
			{
				r += solve2( m, n7, d + 1, f | 0b001 );
			}
		}
	}
	
	return r;
}
