#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;

lint modpow(lint a, lint n, lint m = MOD){
  lint ans = 1;
  while(n>0){
    if(n%2==1) ans *= a; 
    ans %= m;
    a *= a;
    a %= m;
    n /= 2;
  }
  return ans;
}

lint inv(lint a, lint m = MOD){
  return modpow(a, m-2, m);
}

lint gcd(lint a, lint b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}         
  
//////////////////////  
////////////////////
// cout << fixed << setprecision(12);

int main(){
  lint n; cin>>n;
  lint ans = 0;
  for(lint i=1; i<=n; i++){
    bool ok = true;
    lint tmp = i;
    while(tmp>0){
      if(tmp%10==7){
        ok = false;
        break;
      }
      tmp/=10;
    }
    lint tmp2 = i;
    while(tmp2>0){
      if(tmp2%8==7){
        // cout << i << endl;
        ok = false;
        break;
      }
      tmp2/=8;
    }
    if(ok){
      // cout << i << endl;
      ans++;
    }
  }
  cout << ans << endl;
}
    
        
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <float.h>

using namespace std;
using ll = long long;

#define canDbg	0

#define dbg(x)	if(canDbg) cout << x << endl;
#define rep(n, e)	for(ll n = 0;n < e;n++)

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

	stringstream ss;

	int sum = 0;

	for (int n = 1; n <= N; n++)
	{
		string d = to_string(n);

		stringstream ss;
		ss << oct << n;

		string o = ss.str();

		//cout << "dec; " << d << endl;
		//cout << "oct; " << o << endl;

		if ((d.find('7') == string::npos) && (o.find('7') == string::npos))
		{
			sum++;
		}
	}

	cout << sum;

	return 0;
}