#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ull unsigned long long
void testcase(){
    ll n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        bool st=true;
        int j=i;
        while(j){
            if(j%10==7){
                st=false;
                break;
            }
            j/=10;
        }
        j=i;
        while(j){
            if(j%8==7){
                st=false;
                break;
            }
            j/=8;
        }
        if(st){
            ans++;
        }
    }
    cout<<ans;
}
int main() {
    ll t=1;
    //cin>>t;
    while(t--){
        testcase();
        //cout<<'\n';
    }
}

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

#define ll long long
#define ld long double
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define F first
#define S second
#define pll pair<ll, ll>
#define all(v) (v).begin(), (v).end()
#define decimal(n) cout << fixed << setprecision(n)
#define mod 1000000007
// #define mod 998244353
#define pi 3.14159265358979323846

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t = 1, tc;
    //cin >> t;
    for (tc = 1; tc <= t; tc++)
    {
        ll n, i;
        cin >> n;
        ll ans = 0, val = 7;
        set<ll> s;
        for (i = 1; i <= n; i++)
        {
            ll x = i;
            while (x > 0)
            {
                if (x % 10 == 7)
                {
                    s.insert(i);
                    break;
                }
                x /= 10;
            }
            x = i;
            while (x > 0)
            {
                if (x % 8 == 7)
                {
                    s.insert(i);
                    break;
                }
                x /= 8;
            }
        }
        cout << n - s.size();
    }
    return 0;
}