#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a,v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int n;

bool checkDecimal(int x) {
	while (x) {
		int mods = x%10;
		if (mods == 7) return true;
		x /= 10;
	}
	return false;
}

bool checkOctal(int x) {
	while (x) {
		int mods = x%8;
		if (mods == 7) return true;
		x /= 8;
	}
	return false;
}

int main() {
	scanf("%d", &n);
	int ans = 0; 
	for (int i = 1; i <= n; ++i) {
		if (!checkDecimal(i) && !checkOctal(i)) {
			++ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
typedef long long int ll;
int main()
{
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	ll n; cin >> n;
	ll k = 0;
	set<ll> s;
	for (int i = 1; i <= n; i++) {
		ll t = i;
		while (t) {
			if (t % 10 == 7) {
				s.insert(i);
				break;
			}
			t = t / 10;
		}
		t=i;
		while (t) {
			if (t % 8 == 7) {
				s.insert(i);
				break;
			}
			// t = t - ((t / 8) * 8);
			t = t / 8;
		}
	}
// 	for (auto i : s) {
// 		cout << i << " ";
// 	}
	cout << n - s.size();
}