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

long long int to_octal(long long int n)
{
    long long int num = 0, cnt = 1;
    while(n != 0) {
        int r = n % 8;
        num += r * cnt;
        cnt = cnt * 10;
        n /= 8;
    }
    return num;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long int n;
    string o, d;
    cin >> n;
    long long int cnt = n;
    long long int len = to_octal(n);
    for(int i = 1; i <= n; ++i) {
        d = to_string(i);
        size_t find1 = d.find("7");
        long long int x = to_octal(i);
        o = to_string(x);
        size_t find2 = o.find("7");
        if(find1 != string::npos) cnt--;
        else if(find2 != string::npos) cnt--;
    }
    cout << cnt << endl;
}

#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007 // 998244353
#define INFLL (1LL<<62)
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
__attribute__((constructor))
void init(){ std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout<<std::fixed<<std::setprecision(15); }
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ll a1, a2, a3, a4;
    cin >> a1>> a2>>a3>>a4;
    cout << min(min(a1, a2), min(a3, a4)) << endl;
}