#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define bg begin()
#define en end()
#define endl "\n"
#define vvl(n,m) vector<vector<ll> > a( n , vector<ll> (m))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;
ll power(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y / 2, m) % m; 
    p = (p * p) % m; 
  
    return (y % 2 == 0) ? p : (x * p) % m; 
} 
ll modInverse(ll a, ll m) 
{ 
    return power(a, m - 2, m); 
}
ll knapsack(vector<vector<ll>>&dp,ll x,ll i,ll n,ll s[],ll h[]){
    ll r,l;
    if(i>=n || x==0)
        return 0;
    if(dp[i][x]!=-1)
        return dp[i][x];
    if(x>=h[i]){
        l=s[i]+knapsack(dp,x-h[i],i+1,n,s,h);
        r=knapsack(dp,x,i+1,n,s,h);
        return dp[i][x]=max(l,r);
    }
    else
        return dp[i][x]=knapsack(dp,x,i+1,n,s,h);
}
void solve()
{
    ll n,i,p=1,s,t;
    cin>>n;
    ll a[n],j;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    vector<ll> v;
    for(i=0;i<n-1;i++){
        if(a[i]>a[i+1] && a[i+1]>i+1){
            p=0;
            break;
        }
        else if(a[i]>a[i+1]){
            for(j=i+1;j>=a[i+1];j--){
                v.push_back(j);
            }
            a[i+1]=a[i];
        }
    }
    if(p==0 || v.size()!=n-1)
        cout<<"-1";
    else{
        s=v.size();
        for(i=0;i<s;i++){
            cout<<v[i]<<endl;
        }
    }
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    solve();
    #ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define INF 1000000000000000
#define M 1000000007

void solve()
{
	ll n;
	cin>>n;
	ll i,j,k,ans=0;
	ll power[n],speed[n],technique[n],knowledge[n],invent[n];
	ll a1=0,b1=0,c1=0,d1=0,e1=0;
	for(i=0;i<n;i++)
	{
		cin>>power[i]>>speed[i]>>technique[i]>>knowledge[i]>>invent[i];
		a1=max(a1,power[i]);
		b1=max(b1,speed[i]);
		c1=max(c1,technique[i]);
		d1=max(d1,knowledge[i]);
		e1=max(e1,invent[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			ll a[5]={0};
			ll tempa=max(power[i],power[j]);
			ll tempb=max(speed[i],speed[j]);
			ll tempc=max(technique[i],technique[j]);
			ll tempd=max(knowledge[i],knowledge[j]);
			ll tempe=max(invent[i],invent[j]);
			ll mini=min(tempa,min(tempb,min(tempc,min(tempd,tempe))));
			a[0]=tempa;
			a[1]=tempb;
			a[2]=tempc;
			a[3]=tempd;
			a[4]=tempe;
			ll p=0,sum=0;
			if(mini==tempa)
			{
				p++;
				sum=a1;
			}
			if(mini==tempb)
			{
				p++;
				sum=b1;
			}
			if(mini==tempc)
			{
				p++;
				sum=c1;
			}
			if(mini==tempd)
			{
				p++;
				sum=d1;
			}
			if(mini==tempe)
			{
				p++;
				sum=e1;
			}
			if(p==1)
			{
				sort(a,a+5);
				ans=max(ans,min(sum,a[1]));
			}
			else
			{
				ans=max(ans,mini);
			}
		}
	}
	cout<<ans;
}

int main()																						
	{
	    SPEED;
	   	ll t;
	   	//cin>>t;
	   	t=1;
	   	for(ll ii=1;ii<=t;ii++)
	   	{
	   		//cout<<"Case #"<<ii<<": ";

			solve();		
		}
 }

