#include<bits/stdc++.h>
using namespace std;
int n,vis[8],a[3]={3,5,7},ans;

void dfs(long long x)
{
	if(x > n) return;
	if(vis[3] && vis[5] && vis[7]) ans++;
	for(int i = 0; i < 3; i++){
		vis[a[i]]++;
		dfs(x*10+a[i]);
		vis[a[i]]--;
	}
}

int main()
{
	cin >> n;
	dfs(0);
	cout << ans << endl;
	return 0;
}