#include<bits/stdc++.h>
using namespace std;
int check(int n,int base)
{
    int flag=0;
    while(n!=0)
    {
        int rem=(n%base);
        if(rem==7)
        {
            flag=1;
            break;
        }
        n/=base;
    }
    return flag;
}
int main()
{
    int n;
    cin>>n;
    char a[32];
    string b;
    int count=0;
    for(int i=1;i<=n;i++)
    {
        if(check(i,8)==0&&check(i,10)==0)
        count++;       
    }
    cout<<count;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

bool not7(ll x, ll b){
	while(x){
		if(x%b==7) return 0;
		x/=b;
	}
	return 1;
}

bool ok(int x){
	return not7(x,8) and not7(x,10);
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	
	ll ans = 0;
	
	for(int i = 1; i<=n; i++) if(ok(i)) ans++;
	cout << ans << "\n";
}