#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <random>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template<class T> void corner(bool flg, T hoge) {
	if (flg) {
		cout << hoge << endl;
		exit(0);
	}
	else return;
}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
	o << "{" << obj.first << ", " << obj.second << "}"; return o;
}

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}

void YN(bool flg) {
	cout << ((flg) ? "YES" : "NO") << endl;
}

void Yn(bool flg) {
	cout << ((flg) ? "Yes" : "No") << endl;
}

void yn(bool flg) {
	cout << ((flg) ? "yes" : "no") << endl;
}

int main() {
	V<char> a(4);
	a[0] = '0'; a[1] = '3'; a[2] = '5'; a[3] = '7';
	V<string> S;
	REP(i1,4)REP(i2, 4)REP(i3, 4)REP(i4, 4)REP(i5, 4)REP(i6, 4)REP(i7, 4)REP(i8, 4)REP(i9, 4){
		string SS="";
		SS.push_back(a[i1]);
		SS.push_back(a[i2]);
		SS.push_back(a[i3]);
		SS.push_back(a[i4]);
		SS.push_back(a[i5]);
		SS.push_back(a[i6]);
		SS.push_back(a[i7]);
		SS.push_back(a[i8]);
		SS.push_back(a[i9]);
		SS = to_string(stoi(SS));
		S.push_back(SS);
	}
	V<int> b;
	for(int i = 0; i < S.size(); ++i){
		bool flg3 = false, flg5 = false, flg7 = false, flg = false;
		REP(j,S[i].size()){
			if (S[i][j] == '3') flg3 = true;
			else if (S[i][j] == '5') flg5 = true;
			else if (S[i][j] == '7') flg7 = true;
			else { flg = true; break; };
		}
		if (flg) continue;
		if (flg3 && flg5 && flg7) b.push_back(stoi(S[i]));
	}
	sort(ALL(b));
	int N; cin >> N;
	cout << upper_bound(ALL(b), N) - b.begin() << endl;


	return 0;
}



Measured memory_bytes: 14832