#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int i[9];
string re(int i){
	if(i==0){
		return "7";
	}else if(i==1){
		return "5";
	}else{
		return "3";
	}
}
bool judge(int size){
	int se=0, fi=0, th=0;
	for(int j=0; j<size; j++){
		if(i[j]==0){
			se++;
		} else if(i[j]==1){
			fi++;
		} else{
			th++;
		}
	}
	if(se>0&&fi>0&&th>0){
		return true;
	} else{
		return false;
	}
}
int main(void)
{
	int n;

	cin>>n;

	map<int, int> count;

	for(i[0]=0; i[0]<3; i[0]++){
		for(i[1]=0; i[1]<3; i[1]++){
			for(i[2]=0; i[2]<3; i[2]++){
				if(judge(3)){
					string s;
					for(int j=0; j<3; j++){
						s+=re(i[j]);
					}
					count[stoi(s)]++;
				}
				for(i[3]=0; i[3]<3; i[3]++){
					if(judge(4)){
						string s0;
						for(int j1=0; j1<4; j1++){
							s0+=re(i[j1]);
						}
						count[stoi(s0)]++;
					}
					for(i[4]=0; i[4]<3; i[4]++){
						if(judge(5)){
							string s1;
							for(int j2=0; j2<5; j2++){
								s1+=re(i[j2]);
							}
							count[stoi(s1)]++;
						}
						for(i[5]=0; i[5]<3; i[5]++){
							if(judge(6)){
								string s2;
								for(int j3=0; j3<6; j3++){
									s2+=re(i[j3]);
								}
								count[stoi(s2)]++;
							}
							for(i[6]=0; i[6]<3; i[6]++){
								if(judge(7)){
									string s3;
									for(int j4=0; j4<7; j4++){
										s3+=re(i[j4]);
									}
									count[stoi(s3)]++;
								}
								for(i[7]=0; i[7]<3; i[7]++){
									if(judge(8)){
										string s4;
										for(int j5=0; j5<8; j5++){
											s4+=re(i[j5]);
										}
										count[stoi(s4)]++;
									}
									for(i[8]=0; i[8]<3; i[8]++){
										if(judge(9)){
											string s5;
											for(int j6=0; j6<9; j6++){
												s5+=re(i[j6]);
											}
											count[stoi(s5)]++;
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	int ans=0;
	for(map<int, int>::iterator itr=count.begin(); itr!=count.end(); itr++){
		if(itr->first>n) break;
		ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1536