#include <iostream>

using namespace std;

typedef long long ll;

int f(ll k, int b, ll n) {
	if(k > n) return 0;
	else return (b == 7) + f(10 * k + 3, b | 1, n) + f(10 * k + 5, b | 2, n) + f(10 * k + 7, b | 4, n);
}

int main() {
	ll n;
	cin >> n;
	cout << f(0, 0, n) << endl;
	return 0;
}
