#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll decimaltoOctal(ll deciNum)
{
 
    // initializations
    ll octalNum = 0, countval = 1;
    ll dNo = deciNum;
 
    while (deciNum != 0) {
 
        // decimals remainder is calculated
        ll remainder = deciNum % 8;
 
        // storing the octalvalue
        octalNum += remainder * countval;
 
        // storing exponential value
        countval = countval * 10;
        deciNum /= 8;
    }
    return octalNum;
}
int main()
{
    fast
    
    ll n;
    cin>>n;
    ll count=0;
    for(ll i=1;i<=n;i++)
    {
        string str1 = to_string(i);
        string str2 = to_string(decimaltoOctal(i));

        if(str1.find('7') ==string::npos &&  str2.find('7') ==string::npos)
        {
            count++;
        }
        
    }
    cout<<count;

    return 0;
}
// 問題の URL を書いておく
// 

#include <bits/stdc++.h>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    int N;
    cin >> N;
    int ans = 0;
    rep(i, N)
    {
        auto n = i + 1;
        auto dn = n;
        bool valid = true;
        while(dn > 0)
        {
            auto m = dn % 10;
            if(m == 7)
            {
                valid = false;
                break;
            }
            dn /= 10;
        }
        if(!valid) continue;

        auto on = n;
        while(on > 0)
        {
            auto m = on % 8;
            if(m == 7)
            {
                valid = false;
                break;
            }
            on /= 8;
        }
        if(!valid) continue;

        ans++;
    }
    cout << ans << endl;
    return 0;
}
