#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define sz(x) ((int)(x).size()) 
#define all(x) x.begin() , x.end()
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define deb(x) cout<<#x<<"="<<x<<endl
#define debs(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll

const int mod = 1000000007;
const int MAX = INT_MAX;
const int MIN = INT_MIN;
const char nl = '\n';
const long long INF = 1e18; 

int octi(int n){
    int x = 0 , cnt =1 ; 
    while(n!=0){
        int rem = n%8 ;
        x+= rem*cnt ;
        cnt = cnt*10 ;
        n = n/8 ;
    }
    return x ;
}

bool findseven(int n){
    while(n!=0){
        int rem = n%10 ;
        if(rem==7) return true ;
        n/=10 ;
    }
    return false ;
}

void solve(){
    int n ; cin>>n ;
    set<int> ans ; 
    for(int i=1;i<=n;i++){
        if(findseven(i)){
            ans.insert(i);
        }
        int octnum = octi(i) ;
        if(findseven(octnum)){
            ans.insert(i);
        }
    }
     cout<<n - sz(ans) ;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);cout << fixed;
#ifndef ONLINE_JUDGE
    freopen("F:/input.txt", "r", stdin);
    freopen("F:/output.txt", "w", stdout);
#endif
    int T = 1;
   // cin >> T;
    while (T--) {
        solve();
    } 
}
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    bool ok = true;
    for(int base : {8,10}){
      int x = i;
      while( x > 0){
        if(x%base == 7) ok = false;
        x /= base;
      }
    }
    if(ok) ++ans;
  }
  cout << ans << endl;
}