#include<iostream>
#include<math.h>
#include<map>
#include<vector>
using namespace std;
 int  main()
{
    long long int  n;
    cin>>n;
    long long int  ans= n*(n-1)/2;
    map<long long int ,long long int > count;
    long long int  y;
    for (long long int  i = 0; i < n; i++)
    {
        cin>>y;
        count[y]++;
    }

   for (auto it = count.begin();it != count.end(); ++it)

       { 
           if(it->second>0)
        ans= ans- ((it->second)*((it->second)-1))/2;
        }

         cout<<ans;
    

}
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <unordered_set>
#include <queue>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stack>
#include <valarray>
#include <typeinfo>
#include <array>

using namespace std;
using ll=long long;
using P = pair<ll,ll>;

#define rep(i,n) for (int i=0; i<(n);++i)
//ll mod=998244353,fac[1000001],finv[1000001],inv[1000001];
int MOD = 1e9+7,ans=0,n,m;
unordered_set<char> tops;
const double PI = acos(-1);
vector<vector<int>> dir = {{0,1},{1,0},{0,-1},{-1,0}};
const int MAX = 1e5+5;

vector<ll> fac,finv,inv;

int ser(int i,int j,int w,vector<vector<int>> &par){
  if(par[i][j]==i*w+j) return par[i][j];
  else return par[i][j]=par[par[i][j]/w][par[i][j]%w];
}

int main()
{
  int n;
  cin >> n;
  vector<int> pw(n),sp(n),te(n),kn(n),id(n);
  rep(i,n){
    cin >> pw[i] >> sp[i] >> te[i] >> kn[i] >> id[i];
  }
  int l=0,r=1e9+1;
  while(r-l>1){
    int mid=(r+l)/2,out=1;
    vector<int> cnt(32);
    rep(i,n){
      int p=0;
      if(pw[i]>=mid) p+=1;
      if(sp[i]>=mid) p+=2;
      if(te[i]>=mid) p+=4;
      if(kn[i]>=mid) p+=8;
      if(id[i]>=mid) p+=16;
      cnt[p]++;
    }
    //rep(i,32) cout << cnt[i] << ' ';
    //cout << endl;
    rep(i,32){
      rep(j,32){
        rep(k,32){
          if(cnt[i]==0 || cnt[j]==0 || cnt[k]==0) continue;
          rep(l,5){
            if(!((i& (1<<l)) || (j& (1<<l)) || (k& (1<<l)))) break;
            if(l==4) out=0;
          }
        }
      }
    }
    if(out==0) l=mid;
    else r=mid;
    //cout << mid << endl;
  }
  cout << l << endl;
}