#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;
#define cni cin

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int n,m,k,ans=0,ci;
string s;
bool flg;

main(){
	cin>>s;
	if(s[0]<3){
		s[0]=0;
		for(int i=1;i<s.size();i++){
			s[i]=7;
		}
	}/*else{
		rep(i,s.size()){
			//if(flg)break;
			if(s[i]=='3'||s[i]=='5'||s[i]=='7')continue;
			
		}
	}*/
	while(toInt(s)>357){
		for(int i=s.size()-1;i>=0;i--){
			if(s[i]=='3'||s[i]=='5'||s[i]=='7')continue;
			if(i==0){
				if(s[i]<'3')s[i]='0';
				else if(s[i]<'5')s[i]='3';
				else if(s[i]<'7')s[i]='5';
				else s[i]='7';
			}else{
				if(s[i]<'3'){
					s[i]='7';
					s[i-1]--;
				}else if(s[i]<'5'){
					s[i]='3';
					//s[i-1]--;
				}else if(s[i]<'7'){
					s[i]='5';
					//s[i-1]--;
				}else{
					s[i]='7';
				}
			}
		}
		s=toString(toInt(s));
		//debug(toInt(s));
		int c3=0,c5=0,c7=0;
		rep(i,s.size()){
			if(c3&&c5&&c7)break;
			if(s[i]=='3')c3++;
			if(s[i]=='5')c5++;
			if(s[i]=='7')c7++;
		}
		if(c3&&c5&&c7)ans++;
		//debug(s,s.size(),c3);
		if(s.size()==c3){
			//debug("hi");
			string t;
			rep(i,c3-1){
				t+="7";
			}
			s=t;
			//debug(t);
		}else{
			s.back()--;
		}
	}
	dans;
}
