#include<iostream>


using namespace std;

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


int main() {
	int n, res;
	res = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (check(i, 8) && check(i, 10))
			res++;
	}
	cout << res << "\n";
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a;
  cin >> a;
  for(int i =0;i<a.length();i++)
  {
	if(a[i] == '.')
      break;
    cout<< a[i];
  }
}