#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  
  if(n <= 6){
    cout << n << endl;
    return 0;
  }
  int sum = 0;
  for(int i = 7; i <= n; i++){
    int x = i;
    int dif = 0;
    
    do{
      if(x % 10 == 7){
        sum++;
        dif = 1;
        break;
      }
      else{
        x /= 10;
      }
    }while(x != 0);
    
    x = i;
    if(dif == 0){
      do{
        if(x % 8 == 7){
          sum++;
          break;
        }
        else{
          x /= 8;
        }
      }while(x != 0);
    }
    
  }
  
  cout << n - sum << endl;

}
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define fe 2*idx
#define fd fe+1
#define mid (l+r)/2
int aux[1007], n;
int main(){
    fastio; cin>>n;
    int mx = 0, k;
    for(int i=1; i<=n; i++){
        int ai; cin>>ai;
        for(int j=2; j<=ai; j++){
            if(ai%j == 0)aux[j]++;
        }
    }
    for(int i=2; i<=1000; i++){
        if(aux[i] > mx){
            mx = aux[i]; k = i;
        }
    }
    cout<<k<<endl;
}