//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 100009
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
     ll n,i,t,l,r,j,p,x,m;
     cin>>n;
     m=0;
     map<ll,ll>mp;
     f1(i,n)
     {
         mp[i]=0;
     }
     for(i=1;i<=n;i++)
     {
         r=i;
         while(r>0)
         {
             p=r%10;
             r/=10;
             if(p==7)
             {
                 mp[i]=1;
                 break;
             }
         }
         r=i;
         while(r>0)
         {
             p=r%8;
             r/=8;
             if(p==7)
             {
                 mp[i]=1;
                 break;
             }
         }
         if(mp[i]==1)
            m++;
     }
     cout<<n-m<<endl;
}










/**
  *  Author: dhruv_gheewala
  *  Problem: __________
  *  Date:   19.12.2020
  *  Time:   17:40:04
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;
    
    #define fundri 108
    #define debug(...) 1729
#endif

#define endl '\n'
#define int int64_t

typedef pair<int, int> pii;
typedef vector<int> vi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = INT_MAX) {return uniform_int_distribution<int>(l, r)(rng);}

bool in_range(int x, int l, int r) {return l <= x && x <= r;}
template<typename H, typename ...T>void inp(H &head) {cin >> head;}
template<typename H, typename ...T>void inp(H &head, T &...tail) {cin >> head;inp(tail...);}
template<typename T>inline istream &operator >>(istream &in, vector<T> &a) {for(T &x : a)in >> x; return in;}
template<typename T, typename U>inline istream &operator >>(istream &in, pair<T, U> &a) {in >> a.first >> a.second; return in;}

// Multi-Dimension Vector
// Usage: vec<n, data-type> dp(dimention-1, dimention-2, ..., dimention-n, default = data-type())
template<int D, typename T> struct vec : public vector<vec<D - 1, T>>
{
    static_assert(D >= 1, "Vector dimensions must be greater than zero !!");
    template<typename... Args>
    vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)){}
};

template<typename T> struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val){}};

const int inf = 1e15;
const bool testcases = false;

void init_main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef DHRUV_GHEEWALA
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif
}

bool ok(int x)
{
    int y = x;
    while(x > 0) {
        if(x % 10 == 7)
            return false;
        x /= 10;
    }

    while(y > 0) {
        if(y % 8 == 7)
            return false;
        y /= 8;
    }
    return true;
}

int f(int n)
{
    int res = 0;
    for(int i = 1; i <= n; i++) {
        res += ok(i);
    }
    return res;
}

void solve(int tc)
{
    int n;
    cin >> n;

    cout << f(n) << endl;
}

int32_t main(int32_t argc, char **argv)
{
    init_main();

    int TC = 1;
    if(testcases)
        cin >> TC;

    for(int tc = 1; tc <= TC; ++tc) {
        solve(tc);
        fundri;
    }
    return 0;
}