//dragon->emperor
#include <bits/stdc++.h>

using namespace std;

/**********************************************************************************/

#define mod 1000000007
#define mod2 998244353
const double pi = acos(-1);
#define inf 1e18+5
#define iinf 1e9+5

#define ll long long
#define ld  long double
#define fl(i,a,n) for(ll i=a;i<n;i++)
#define lf(i,a,n) for(ll i=n-1;i>=a;i--)
#define read(n) ll n; cin>>n;
#define scan(a,n) vector<ll> a(n); for(ll i=0;i<n;i++) cin>>a[i];
#define print(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endll;
#define p(n) cout<<n<<endll;

#define endll "\n"
#define pb push_back
#define mp make_pair
#define dec(n) fixed<<setprecision(n)
#define F first
#define S second
#define I insert
#define E end()
#define B begin()

#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define reverseall(x) reverse(all(x))

typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef map<ll,ll> mll;
typedef vector<pll> vpl;
/*************************************[DEBUG]**************************************/
 
void debug(ll x) { cout<<x<<endll;}
void debug(int x) { cout<<x<<endll;}
void debug(unsigned int x) { cout<<x<<endll;}
void debug(unsigned ll x) { cout<<x<<endll;}
void debug(float x) { cout<<x<<endll;}
void debug(double x) { cout<<dec(7)<<x<<endll;}
void debug(ld x) { cout<<dec(15)<<x<<endll;}
void debug(char x) { cout<<'\''<<x<<'\''<<endll;}
void debug(string s) {cout<<'\"'<<s<<'\"'<<endll;}
void debug(vector<ll> v) { for(auto x :v) cout<<x<<" "; cout<<endll;}
void debug(bool bb)  { cout<<(bb? "True":"False")<<endll;} 
void debug(map<ll,ll>mpp) { for(auto x :mpp) cout<<x.first<<" "<<x.second<<endll;}
void debug(pair<ll, ll> pp) { cout<<"{"<<pp.first<<","<<pp.second<<"}"<<endll;} 
void debug(vector<pair<ll,ll>> v) { for(auto x :v) debug(x);}

/***********************************[FUNCTIONS]************************************/

// bitset<200000>vis(0);
vector<bool> prime;

void primes(ll n)
{
    prime.resize(n+1);
    prime.assign(n+1,true);
    prime[0]=0;
    prime[1]=0;
    for(ll i=2; i*i<=n; i++)
    {
        if(prime[i])
        {
            for(ll j=(i*i); j<n; j=j+i) prime[j]=false;
        }
    }
}

ll gcd(ll x, ll y)
{
    if(x==0) return y;
    return gcd((ll) y%x, (ll)x);
}

ll powM(ll x, ll y, ll m)
{
    ll ans=1, r=1;
    x=x%m;
    while(r>0 && r<=y)
    {
        if(r & y)
        {
            ans=ans*x;
            ans=ans%m;
        }
        r=r<<1;
        x=x*x;
        x=x%m;
    }
    return ans;
}

ll powN(ll a,ll n)
{
    if(n==0) return 1;
    if(n==1) return a;
    ll u=powN(a,n/2);
    u=u*u;
    if(n%2) u=u*a;
    return u;
}

ll modinv(ll a,ll m)
{
    return powM(a,m-2,m);
}

ll ncr(ll n, ll r, ll m)
{
    if(n<r) return 0;
    if(n==r || r==0) return 1;
    if(r==1) return n;
    if(n-r<r) return ncr(n,n-r,m);
    ll a=n;
    ll b=r;
    for(ll i=1; i<r; i++)
    {
        a=(a*(n-i))%m;
        b=(b*(r-i))%m;
    }
    b=modinv(b,m);
    a=(a*b)%m;
    return a;
}

/************************************[CODE]****************************************/

bool solve(ll num, ll k)
{
    ll n=1;
    while(n<num)
        n=n*k;
    while(num>0)
    {
        if(num/n==7) return false;
        num=num%n;
        n=n/k;
    }
    return true;
}

int main()
{
    ll n; cin>>n;
    ll ans=0;
    fl(i,1,n+1)
    {
        if(solve(i,10) && solve(i,8)) ans++;
    }
    p(ans);
    return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
#include <string>
#include <cstdio>
#include <cmath>
#include <climits>
using namespace std;

const long long INF = 1000000007;

typedef pair<int, int> P;
template<class T>
T gcd(T a, T b)
{
    if (a % b == 0) return b;
    else return gcd(b, a%b);
}

bool include7(int N)
{
    while(N > 0)
    {
        int i = N % 10;
        if (i == 7)
        {
            return true;
        }
        
        N /= 10;
    }

    return false;
}

int to8(int N)
{
    int hold8 = 1;
    int hold10 = 1;
    int ans = 0;

    while(N >= hold8)
    {
        hold8 *= 8;
        hold10 *= 10;
    }
    if (hold8 >= 8)
    {
        hold8 /= 8;
        hold10 /= 10;
    }

    while(N > 0)
    {
        ans += hold10 * min(7, N / hold8);
        N -= hold8 * min(7, N / hold8);
        
        hold8 /= 8;
        hold10 /= 10;
    }

    return ans;
}

int main(void)
{
    int N;
    cin >> N;

    vector<bool> flag(N+1, false);
    // 10
    for (int i = 1; i <= N; i++)
    {
       if (include7(i))
       {
           flag[i] = true;
       }
    }

    // 8
    for (int i = 1; i <= N; i++)
    {
        int p = to8(i);
        if (include7(p))
       {
           flag[i] = true;
       }
    }

    int count = 0;
    for (int i = 0; i <= N; i++)
    {
        if (flag[i])
        {
            count++;
        }
        
    }
    
    
    cout << N - count << endl;
}