#include <bits/stdc++.h>

int limit = 0;
using namespace std;
int n,m,gtln,d,x;
int dd[100001];
int main()
{
	freopen("LSEQ.inp","r",stdin);
	freopen("LSEQ.out","w",stdout);
	ios_base::sync_with_stdio(false);
    cin>>m;
    for (int i=0;i<m;i++)
    {
        cin>>x;
        limit=max(limit,x);
        dd[x]=1;
        if (x==0) d++;
    }
    for (int i=0;i<limit;i++)
    {
        dd[i]=1-dd[i];
    }
    for (int i=1;i<limit;i++)
    {
        dd[i]+=dd[i-1];
    }
    int i=0,j=1;
    while (i<=limit&&j<=limit)
    {
        if (dd[j]-dd[i]<=d)
        {
            gtln=max(gtln,j-i);
            j++;
        }
        else i++;
    }
    cout<<x;
}

