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

llong N;
llong cnt;

void rec(llong num, int use) {
	if (num > N) return;
	if (use == 0b111) cnt++;

	rec(num * 10 + 3, use | 0b001);
	rec(num * 10 + 5, use | 0b010);
	rec(num * 10 + 7, use | 0b100);
	return;
}

int main(void) {
	cin >> N;
	rec(0, 0);
	cout << cnt << endl;
	return 0;
}