import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto N = readln.split[0].to!int;
	
	// p = 10^^k <= N < 10^^(k+1)
	int p = 1, k = 0;
	foreach (i; 0 .. 10) {
		if (p <= N && N < p*10) break;
		p *= 10; k += 1;
	} 
	
	int result;
	foreach (num; all(k+1)) {
		if (num > N) break;
		if (has(num, 3) && has(num, 5) && has(num, 7)) result++;
	}
	
	result.writeln;
}

// does n has m in its digit
bool has(int n, int m) {
	if (n < 10) return n == m;
	int n_ = n/10;
	return m == n - n_*10 || has(n_, m);
}

int[] generate(int n) {
	if (n == 1) return [3, 5, 7];
	auto next = generate(n-1);
	int[] result;
	foreach (num; next) { result ~= [num*10+3, num*10+5, num*10+7]; }
	return result;
}

int[] all(int n) {
	if (n == 1) return generate(1);
	else return all(n-1) ~ generate(n);
}