#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod  1000000007
#define inf 900000000000000LL
#define M 200005

using namespace std;
int vis[400005];
int ar[400005];
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    int cnt = 0;
    for(int i=1;i<=n;i++)
    {
        int d = i;
        int f=1;
       while(d)
        {
            if(d%10==7)
            {
                f=0;
                break;
            }
            d/=10;
        }
        if(f==0)
        {
            cnt++;
            continue;
        }
        d = i;
        while(d)
        {
            if(d%8==7)
            {
                f=0;
                break;
            }
            d/=8;
        }
        if(f==0) cnt++;
    }
    cout << n-cnt << endl;
    return 0;
}


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

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        bool ok = true;
        for (int x = i; ok && x; x /= 10) {
            ok &= (x % 10) != 7;
        }
        for (int x = i; ok && x; x /= 8) {
            ok &= (x % 8) != 7;
        }
        ans += ok;
    }
    cout << ans << '\n';
    return 0;
}