#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;

static const int  MAX_INT  = std::numeric_limits<int>::max(); // 2147483647 = 2^31-1
static const long MAX_LONG = std::numeric_limits<long>::max();
static const ll   MAX_LL   = std::numeric_limits<long long>::max();
static const int  INF      = (1 << 30);

#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////

ll cnvtoN(ll ten, ll n) {
    ll res = 0;
    ll factor = 1;
    while (ten > 0) {
        res += (ten % n) * factor;
        ten /= n;
        factor *= 10;
    }
    return res;
}

//bool hasSeven(ll nbin) {
//    ll tgtNb = nbin;
//    while (tgtNb > 0) {
//        const ll res = tgtNb % 10;
//        if (res == 7) return true;
//        tgtNb /= 10;
//        if (tgtNb == 0) break;
//    }
//}

void Main() {
    ll N; cin >> N;

    ll cnt = 0;

    for (ll i = 1; i <= N; ++i) {
        // ten
        // if (hasSeven(i)) continue;
        bool hasS = false;
        ll tgtNb = i;
        while (tgtNb > 0) {
            const ll res = (tgtNb % 10);
            if (res == 7) {hasS = true; break;};
            tgtNb /= 10;
        }
        if (hasS) continue;

        // e
        ll ite = cnvtoN(i, 8);
        // if (hasSeven(e)) continue;
        tgtNb = ite;
        while (tgtNb > 0) {
            const ll res = (tgtNb % 10);
            if (res == 7) {hasS = true; break;};
            tgtNb /= 10;
        }
        if (hasS) continue;
        ++cnt;
    }
    cout << cnt << endl;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	double tmp;
	cin >> tmp;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
	long long n,ans=0;
	cin>>n;
	if (n>=1000)	
		ans+=n-999;
	if (n>=1000000)	
		ans+=n-999999;
	if (n>=1000000000)	
		ans+=n-999999999;
	if (n>=1000000000000)
		ans+=n-999999999999;
	if (n>=1000000000000000)	
		ans+=n-999999999999999;
	cout<<ans;
	return 0;
}