#include <bits/stdc++.h>
using namespace std;

int N,ret;

int count753(long i, bool _3, bool _5, bool _7) {
	if (i > N) {
		return 0;
	}
	if (_3 && _5 && _7) {
		ret++;
	}
	count753(i * 10 + 3, true, _5, _7);
	count753(i * 10 + 5, _3, true, _7);
	count753(i * 10 + 7, _3, _5, true);
	return ret;
}

int main() {
	cin >> N;
	cout << count753(0,false,false,false) << endl;
}