///created: 29/May/2019 10:17:32

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll n, ans = 0;

void dfs(ll u, int s) {
	if (u > n) return;
	if (s == 7) ans++;
	dfs(u * 10 + 7, s | 1);
	dfs(u * 10 + 5, s | 2);
	dfs(u * 10 + 3, s | 4);
}

int main() {
	scanf("%lld", &n);
	dfs(0, 0);
	printf("%lld", ans);
	return 0;
}
