#include<bits/stdc++.h>
using namespace std;
class Abc
{
public:
    int solve(int n)
    {
        int temp=0,temp1=0,p=0,q=0,f=0;
        p=n,q=n;
        while(p>0 && q>0)
        {
            temp=p%10;
            if(temp==7)
            {
                f=1;
                break;
            }
            temp1=q%8;
            if(temp1==7)
            {
                f=1;
                break;
            }
            p=p/10;
            q=q/8;
        }

        return f;
    }
};

int main()
{
    Abc ob;
    int n,i,cnt=0;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        if(ob.solve(i)==1)
            cnt++;
    }
    cout<<n-cnt<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define ld double
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--) 
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<double>	vd;
typedef vector<bool>	vb;
typedef pair<ll,ll> 	pll;
#define br "\n"
#define ff first
#define ss second
#define gcd __gcd
#define debug(a...) cout<<#a<<": ";for(auto it:a)cout<<it<<" ";cout<<endl;
ll MAX = 1e6 + 1;
#define MAXIM 200005
ll mod = 1e9 + 7;


void solve(){
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i,1,n + 1){
        ll t1 = i,t2 = i;
        bool f1 = true,f2 = true;
        while(t1 > 0){
            if(t1 % 10 == 7) f1 = false;
            t1 /= 10;
        }
        while(t2 > 0){
            if(t2 % 8 == 7) f2 = false;
            t2 /= 8;
        }
        if(f1 && f2) ans++;
    }
    cout << ans;
}
 

int main(){ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
    
	ll t = 1;
    // cin >> t;
    // calc();
	rep(i,0,t){
        // cout << "Case #" << i + 1 << ": ";
        solve();
        // test();
	}
}