#include <bits/stdc++.h>
#include <string.h>
#include <cmath>
#include <math.h>
#include <stdio.h>
using namespace std;

bool check(int x){
	string str;
	str = to_string(x);
	if (str.find("3") == std::string::npos)
		return false;
	if (str.find("5") == std::string::npos)
		return false;
	if (str.find("7") == std::string::npos)
		return false;
	return true;
}

int main(){
	int N;
	cin >> N;
	int index = 0;
	int SHICHI[29523];
	SHICHI[0] = 3;
	SHICHI[1] = 5;
	SHICHI[2] = 7;
	for(int i=1;i<9;i++){
		int l = pow(3,i);
		for(int k=0;k<l;k++){
			SHICHI[l + index + k * 3] = SHICHI[index + k] * 10 + 3;
			SHICHI[l + index + k * 3 + 1] = SHICHI[index + k] * 10 + 5;
			SHICHI[l + index + k * 3 + 2] = SHICHI[index + k] * 10 + 7;
		}
		index = index + l*3;
	}
	int Num = 0;
	for(int j=0;j<29523;j++){
		if (chack(SHICHI[j]) && SHICHI[j] <= N)
			Num++;
	}
	cout << Num << endl;
}