#include <bits/stdc++.h>

#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	int n; cin>>n;
	int cnt = 0;
	rep(i,n)
	{
		int tmp = i + 1;
		int f = 1;
		string o;
		while (tmp)
		{
			o.push_back((char)(tmp % 8 + '0'));
			tmp /= 8;
		}
		rep(i,o.size())
			if (o[i] == '7') {cnt++; f = 0; break;}
		tmp = i+1;
		string d = to_string(tmp);
		rep(i,d.size())
			if (d[i] == '7' && f) {cnt++; break;}
	}
	cout << n - cnt << "\n";
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll mod=1e9+7;

vector<ll> p(3e5),r(3e5);

ll find(ll a){
    if(p[a]==a)
    return a;
    return p[a]=find(p[a]);
}

void join(ll a,ll b){
    a=find(a);
    b=find(b);
    
    if(r[a]==r[b]){
        r[a]++;
    }
    
    if(r[a]>r[b]){
        p[b]=a;
    }else{
        p[a]=b;
    }
    
}


 
int main() {
   
    ll n;
    cin>>n;
    
     ll a[n];
     
     for(int i=0;i<n;i++){
         cin>>a[i];
     }
     
     for(int i=0;i<p.size();i++){
         p[i]=i;
     }
     
     int i=0,j=n-1;
     
     ll ans=0;
     
     while(i<j){
         if(a[i]!=a[j]){
             ll c=find(a[i]);
             ll d=find(a[j]);
             
             if(c==d){
                 i++;
                 j--;
                 continue;
             }else{
                 ans++;
                 join(a[i],a[j]);
             }
         }
         i++;
         j--;
     }
     
     cout<<ans;
     
     
     
 	return 0;
}
