#include <iostream>

using namespace std;

#define ll long long

ll n, ans;

void DFS(ll a, ll b, ll c, ll x)
{
	if (x > n) return;
	if (a && b && c) ans++;

	DFS(1, b, c, x * 10 + 3);
	DFS(a, 1, c, x * 10 + 5);
	DFS(a, b, 1, x * 10 + 7);
}

int main()
{
	cin >> n;

	DFS(0, 0, 0, 0);

	cout << ans << endl;
}