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

int N;
int ans = 0;

void dfs ( int len, string S, int bit )
{
	if ( len > 9 || (S != "" && stoi(S) > N) ) return;
	if ( bit == 7 ) ans++;
	dfs( len + 1, S + '3', bit | 1 );
	dfs( len + 1, S + '5', bit | 2 );
	dfs( len + 1, S + '7', bit | 4 );
}

int main()
{
	cin >> N;

	dfs(0, "", 0);

	cout << ans << endl;
}
