#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pair<int,int>>;



void solve() {
    // 前計算
    vector<int> v((1e5)+1,0);
    auto haveSevenInEight = [](auto &&f,int val)-> bool {
        if(val%8 == 7) return true;
        if(val > 8) return f(f,val/8);
        return false;
    };
    auto haveSeven = [](int val) -> bool {
        auto s = to_string(val);
        if(any_of(ALL(s),[](char c) { return c == '7'; })) return true;
        return false;
    };
    v[1] = 1;
    FOR(i,2,(1e5)+1) {
        bool find = haveSeven(i) || haveSevenInEight(haveSevenInEight,i);
        v[i] = v[i-1] + !find;
    }
    int N; cin >> N;
    cout << v[N] << endl;
}

int main() {
    solve();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

const int N = 1e6;

int length(int x)
{
	int cnt = 0;
	while(x) cnt ++, x /= 10;
	return cnt;
}

int main()
{
	// freopen("1.in", "r", stdin);
	LL n;
	cin >> n;
	int res = 0;
	for(int i = 1; i < N; ++ i)
	{
		int j = length(i);
		if((LL)i * pow(10, j) + i > n) break;
		res ++;
	}
	cout << res << endl;
}