#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 1; i <= n; i++)
#define rep2(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int i,j,N; cin >> N;
    vector<bool> A(N+1,true);
    string S;
    rep(i,N){
      S = std::to_string(i);
      
      rep2(j,S.size()){
        if(S[j] == '7'){
          A[i] = false;
          break;
        }
      }

      if(A[i]==false){
        continue;
      }
      
      stringstream K;
      K << std::oct << i;
      S = K.str();

      rep2(j,S.size()){
        if(S[j] == '7'){
          A[i] = false;
          break;
        }
      }
    }

    int ans = 0;

    rep(i,N){
      if(A[i]) ans++;
    }
    AA(ans);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#ifdef LOCAL
    #include "trace.h"
#else
    #define trace(args...)
#endif
 
ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}

bool isVal(ll n, ll base){
    while(n>0){
        ll rem = n%base;
        if(rem==7) return false;
        n = n/base;
    }
    return true;
}

void solve(){
    ll n; cin>>n;
    ll ans = 0;
    for(ll i = 1; i<=n; i++)
        ans += isVal(i, 10)&&isVal(i, 8);
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifdef LOCAL
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        freopen("err.txt", "w", stderr);
    #endif
    int t=1;
    // cin>>t;  
    while(t--)
        solve();
}