#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

 bool check(ll K) {
   string S=to_string(K);
   for(auto x:S) {
     if(x=='7') {
       return false;
     }
   }
   return true;
 }

ll  hachi(ll k) {
  ll t=1;
  ll s=0;
while(k>=8) {
  s+=(k%8)*t;
  k/=8;
  t*=10;
}
s+=t*k;
return s;
}


  



int main() {
 ll N;
 cin>>N;
ll ans=0;
 for(ll i=1;i<=N;i++) {
   ll p=hachi(i);
   if(check(i)&&check(p)) {
     ans++;
   }
 }

 cout<<ans<<endl;
}
   
#include <bits/stdc++.h>
using namespace std;

bool check(int i){
     
     for(int j = i; j > 0; j /= 10){
          if(j % 10 == 7){
              // cout << j << endl;
               return true;
          }
     }

     for(int k = i; k > 0; k /= 8){
          if(k % 8 == 7){
              // cout << k << endl;
               return true;
          }
     }

     return false;
}

int main(){
    int N, ans = 0; cin >> N;

    for(int i = 1; i <= N; i++){
         if(check(i) == true){
              ans += 1;
         }
    } 

    cout << N - ans << endl;

     return 0;
}