#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define INF 0x3f3f3f3f
#define f first
#define s second
#define FOR(i, n) for(int i = 1; i <= n; i ++)
#define FFOR(i, a, b) for(int i = a; i <= b; i ++)
#define pii pair<int, int>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define mem(x, a) memset(x, a, sizeof(x))
#define loli ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int maxn = 1e6 + 50;
int n;

bool check(int x) {
	int t = x;
	while(t) {
		if(t % 10 == 7) return 0;
		t /= 10;
	}
	t = x;
	while(t) {
		if(t % 8 == 7) return 0;
		t /= 8;
	}
	return 1;
}

signed main(){
	loli;
	cin >> n;
	int ans = 0;
	FOR(i, n) {
		ans += check(i);
	}
	cout << ans << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long 

bool check(int n,int m){
    while(n){
        if(n % m == 7)return true;
        n/=m;
    }
    return false;
}

void solve(){
    int n;
    cin>>n;
    int c = 0;
    for(int i = 1;i<=n;i++){
        if(check(i,8) || check(i,10))c++;
    }
    cout<<n-c;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    while(t--)solve();
    return 0;
}