#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>

using namespace std;
typedef long long ll;
///定義場所///
int i, j, k, l, m, n;
int N, M, K;
ll MOD = 1000000007;
int ans = 0;
int keta = 1;

//関数リスト//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
//(注)pairの型・比較する場所(first/second)は毎回変えて使用する
bool pairCompare(const pair<ll, ll> firstElof, pair<ll, ll> secondElof)
{
	return firstElof.second > secondElof.second;
}
//////////////
void dfs(ll I, int depth,int three,int five,int seven) {
	if (depth == keta) {
		if (I <= N && three != 0 && five != 0 && seven != 0) {
			ans++;
		}
	}
	else {
		if (three != 0 && five != 0 && seven != 0) {
			ans++;
		}
		dfs(I + 3 * pow(10, depth), depth + 1, three + 1, five, seven);
		dfs(I + 5 * pow(10, depth), depth + 1, three, five + 1, seven);
		dfs(I + 7 * pow(10, depth), depth + 1, three, five, seven + 1);
	}
}

int main()
{
	cin >> N;
	ll I = N;
	while (I / 10 > 0) {
		keta++;
		I /= 10;
	}
	dfs(3, 1, 1, 0, 0);
	dfs(5, 1, 0, 1, 0);
	dfs(7, 1, 0, 0, 1);
	cout << ans;
}