#include<algorithm>
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define neinf 0xc0c0c0c0c0c0c0c0ll
#define inf 0x3f3f3f3f3f3f3f3fll
#define uint unsigned int
#define ull unsigned ll
#define HgS 1000000007
#define ll long long
#define reg register
#define opr operator
#define ret return
#define gc getchar
#define pc putchar
#define cst const
#define db double
#define il inline
il ll rd()
{
	reg ll res=0,lab=1;
	reg char ch=gc();
	while((ch<'0'||ch>'9')&&ch!=EOF)
	{if(ch=='-')lab=-lab;ch=gc();}
	while(ch>='0'&&ch<='9')
		res=(res<<3)+(res<<1)+(ch&15),ch=gc();
	return res*lab;
}
il void prt(ll x,char t='\n')
{
	static char ch[40];reg int tp=0;
	if(!x){fputs("0",stdout);if(t)pc(t);return;}
	if(x<0)pc('-'),x=-x;
	while(x)ch[++tp]=(x%10)^48,x/=10;
	while(tp)pc(ch[tp--]);
	if(t)pc(t);
}
il ll umax(ll a,ll b){return a>b?a:b;}
il ll umin(ll a,ll b){return a<b?a:b;}
il ll uabs(ll x){return x>0?x:-x;}
il ll qpow(ll n,ll e=HgS-2,ll p=HgS)
{
	reg ll res=1;
	while(e){if(e&1)res=res*n%p;n=n*n%p;e>>=1;}
	return res;
}
ll n,ans=inf;
int main()
{
	n=rd();
	for(int i=0;i<=62;++i)ans=umin(ans,i+(n>>i)+n-((n>>i)<<i));
	prt(ans);
	return 0;
}

#include <bits/stdc++.h>
#define ll long long 
#define db(x) cout << (#x) << " = " << x << "\n" ;
#define pb push_back
using namespace std;
set <ll> ok;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE 
  freopen("input.txt", "r", stdin); 
  freopen("output.txt", "w", stdout); 
  #endif 
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i=7;i<=n;i++){
    ll f = 0 , x = i;
    while(x){
      if(x%10==7){
        f = 1;
        break;
      }
      x = x/10;
    }
    x = i;
    while(x){
      if(x%8==7){
        f = 1;
        break;
      }
      x = x/8;
    }
    ans += f;
  }
  cout << n - ans << endl;
  return 0;
}  