#include <bits/stdc++.h>
using namespace std;
int n;
bool validDec(int value){
    bool ret = true;
    while(value>0){
        if(value%10==7){
            ret = false;
            break;
        }
        value /= 10;
    }
    return ret;
}
bool validOct(int value){
    bool ret = true;
    while(value>0){
        if(value%8==7){
            ret = false;
            break;
        }
        value /= 8;
    }
    return ret;
}
int main(){
    cin >> n;
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        if(validDec(i)&&validOct(i))ans++;
    }
    cout << ans << endl;
    return 0;
}
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"

using namespace std;
using namespace __gnu_pbds;

#define pb              push_back
#define vi              vector<int>
#define ll              long long int
#define us              unsigned long long int
#define dig(n)          floor(log10(n)) + 1
#define all(x)          (x).begin(),(x).end()
#define zrobits(x)      __builtin_ctzll(x)
#define setbits(x)      __builtin_popcountll(x)
#define f(i, a, b)      for (int i = a; i < b; i++)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define uniq(v)         (v).erase(unique(all(v)),(v).end())
#define CP()            ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int32_t MOD = 1e9 + 7;
const int32_t mod = 998244353;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update>indexed_set;

bool fx(int n){
	string s;
	string $s=to_string(n);
	while(n){
		s=to_string(n%8)+s;
		n/=8;
	}
	s+=$s;
	for(auto x:s){
		if((x-'0')==7)
			return false;
	}
	return true;
}

auto main() -> int {
  CP()
  ll t;
  t=1;
  // cin>>t;
  while (t--) {
  	int n;
  	cin>>n;
  	int ans(0);
  	for(int i=1;i<=n;i++){
  		(fx(i))?ans++:n=n;
  	}
  	cout<<ans<<endl;
  }
}
