#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=1;i<=(n);++i)
#define rep3(i,i0,n) for(ll i=i0;i<(n);++i)
#define rrep(i,n) for(ll i=((n)-1); i>=0; --i)
#define rrep2(i,n) for(ll i=(n); i>0; --i)
#define pb push_back
#define mod 1000000007
#define fi first
#define se second
#define len(x) ((ll)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
using Pi = pair< ll, ll >;
using vl = vector<ll>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<Pi>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

const ll INF = 1LL << 60;
const ld PI = 3.1415926535897932385;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
void printb(ll N,ll d=16){
    rep(i,d){
        cout<<(N/(1<<(d-i-1)))%2;
    }
    cout<<endl;
    
}
void printv(vector<ll>a){
    rep(i,a.size()){
        if(i==a.size()-1){
            cout<<a[i]<<endl;
        }else{
            cout<<a[i]<<" ";
        }
    }
}
bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


//const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1};
//const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
vvl A;
ll N;
// index が条件を満たすかどうか
bool isOK(ll idx, ll key) {
    vvl B(N,vl(5));

    rep(i,N){
        rep(j,5){
            if(A[i][j]>=idx){
                B[i][j]=1;
            }else{
                B[i][j]=0;
            }
        }
    }

    vl C(N);
    vector<ll>m(1000);
    rep(i,N){
        rep(j,5){
            C[i]+=(B[i][j]<<(5-j-1));
        }
        m[C[i]]=1;
    }

    rep(i,32){
        rep(j,32){
            rep(k,32){
                if(m[i]==1 && m[j]==1 &&m[k]==1){
                    if((i|j|k)==31){
                        return 1;
                    }
                }
            }
            
        }
    }

    return 0;
}
// 汎用的な二分探索のテンプレ
ll binary_search(ll key) {
    ll ng = INF; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll ok = 0; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
    
    cin>>N;
    A=vvl(N,vl(5));

    rep(i,N){
        rep(j,5){
            cin>>A[i][j];
        }
    }

    ll ans=binary_search(0);

    cout<<ans<<endl;







    return 0;
    

}
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
typedef long long ll; 
const int inf = INT_MAX / 2; 
const ll infl = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    int A[N], B[N];
    rep(i,0,N){
        cin >> A[i] >> B[i];
    }
    int min_time = inf;
    rep(i,0,N){
        rep(j,0,N){
            if(i == j){
                int time = A[i] + B[i];
                min_time = min(time,min_time);
            }else{
                int time = max(A[i], B[j]);
                min_time = min(time,min_time);
            }
        }
    }
    cout << min_time << endl;
}