#include <iostream>
using namespace std;
int S;
int ans;
void dfs(long long x , int mask)
{
	if (x > S) return;
	if (mask == 7) ans++;
	dfs(x * 10 + 3 , mask | 1);
	dfs(x * 10 + 5 , mask | 2);
	dfs(x * 10 + 7 , mask | 4);
}
int main()
{
	ans = 0;
	cin >> S;
	dfs(0 , 0);
	cout << ans << endl;
	return 0;
}