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

bool HasSevenInDecimal(int n) {
    while (n != 0) {
        if (n % 10 == 7) {
            return true;
        } 
        n = n / 10;
    }
    return false;
}

bool HasSevenInOctal(int n) {
    while (n != 0) {
        if (n % 8 == 7) {
            return true;
        }
        n = n / 8;
    }
    return false;
}

int main() {
    int N;
    cin >> N;

    int answer = 0;
    for (int i = 1; i <= N; ++i) {
        if (HasSevenInDecimal(i)) {
            continue;
        }
        if (HasSevenInOctal(i)) {
            continue;
        }
        answer++;
    }

    cout << answer << endl;

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define int ll
#define maxn 200001

int N;
int pow8[maxn];

string to_octal(int n){
	string ans = "";
	DEC(i,6,0){
		ans += to_string(n / pow8[i]);
		n %= pow8[i];
	}
	return ans;
}
int32_t main(){
	fast;
	
	cin >> N;
	
	pow8[0] = 1;
	FOR(i,1,6) pow8[i] = pow8[i-1] * 8;
	
	int ans = 0;
	FOR(i,1,N){
		bool yes = 1;
		aFOR(j,to_string(i)){
			if (j == '7') yes = 0;
		}
		aFOR(j,to_octal(i)){
			if (j == '7') yes = 0;
		}
		ans += yes;
	}
	cout << ans << '\n';
}
