// #pragma GCC optimize("Ofast,no-stack-protector")
#pragma comment(linker,"/STACK:36777216")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>

using namespace std;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define PRF(...) printf(__VA_ARGS__)
#define MS(x,v) memset((x),(v),sizeof(x))
#define MS0(x) memset((x),0,sizeof(x))
#define PAR(x,n) for(int ___=0;___<(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define PAR1(x,n) for(int ___=1;___<=(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define PDE1(a) cout<<#a<<" = "<<(a)<<'\n'
#define PDE2(a,b) cout<<#a<<" = "<<(a)<<" , ", PDE1(b)
#define PDE3(a,b,c) cout<<#a<<" = "<<(a)<<" , ", PDE2(b,c)
#define PDE4(a,b,c,d) cout<<#a<<" = "<<(a)<<" , ", PDE3(b,c,d)
#define PDE5(a,b,c,d,e) cout<<#a<<" = "<<(a)<<" , ", PDE4(b,c,d,e)
#define PDE(...) macro_dispatcher(PDE, __VA_ARGS__)(__VA_ARGS__)
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define FIN freopen("in","r",stdin)
#define FOUT freopen("out","w",stdout)
#define DEBUG 1
#else
#define PDE(...) ;
#define PDE1(a) ;
#define PDE2(a,b) ;
#define PDE3(a,b,c) ;
#define PDE4(a,b,c,d) ;
#define PDE5(a,b,c,d,e) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define getchar gtx
#define FIN ;
#define FOUT ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>

template<typename TA,typename TB> ostream& operator<<(ostream& ostm, const pair<TA,TB> &p){ostm<<"("<<p.X<<","<<p.Y<<")";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm, const vector<T> &v){ostm<<"[ ";for(auto i:v)ostm<<i<<" ";ostm<<"]";return ostm;}
template<typename TA,typename TB> ostream& operator<<(ostream &ostm, const map<TA,TB> &mp){ostm<<"[ ";for(auto &it:mp)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const set<T> &s){ostm<<"[ ";for(auto &it:s)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const stack<T> &inp){stack<T> st=inp;ostm<<"[ ";while(!st.empty()){ostm<<st.top()<<" ";st.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const queue<T> &inp){queue<T> q=inp;ostm<<"[ ";while(!q.empty()){ostm<<q.front()<<" ";q.pop();}ostm<<"]";return ostm;}
template<typename TA,typename TB,typename TC> ostream& operator<<(ostream &ostm,const priority_queue<TA,TB,TC> &inp){priority_queue<TA,TB,TC> pq=inp;ostm<<"[ ";while(!pq.empty()){ostm<<pq.top()<<" ";pq.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const deque<T> &inp){deque<T> dq=inp;ostm<<"[ ";while(!dq.empty()){ostm<<dq.front()<<" ";dq.pop_front();}ostm<<"]";return ostm;}
// ostream& operator<<(ostream &ostm,const __int128 &val){__int128 cpy=val; stack<int> st; while(cpy)st.push(cpy%10),cpy/=10; while(st.size())ostm<<st.top(),st.pop();return ostm;}

// #define getchar gtx
// #define fread fread_unlocked
inline char gtx(){
    const int N=1048576;
    static char __buffer[N];
    static char *__p=__buffer,*__end=__buffer;
    if(__p==__end){
        if((__end=__buffer+fread(__buffer,1,N,stdin))==__buffer)return EOF;
        __p=__buffer;
    } return *__p++;
}

template<typename T>
inline bool rit(T &x){
    char c=0; bool fg=0;
    while(c=getchar(), (c<'0' && c!='-') || c>'9')if(c==EOF)return false;
    c=='-' ? (fg=1,x=0) : (x=c&15);
    while(c=getchar(), c>='0' && c<='9')x=x*10+(c&15);
    if(fg)x=-x; return true;
}
template<typename T,typename ...Args>
inline bool rit(T& x,Args& ...args){return rit(x)&&rit(args...);}

/* template<class T>void writeInt(T x, char endc = '\n'){
    static char _buf[4096],*ptr=_buf,*end=_buf+4096;
    if(x<0)*ptr++='-',x=-x; if(x==0)*ptr++='0';
    char* s=ptr;
    while(x){T t=x/10; char c=x-10*t+'0'; *ptr++=c; x=t;}
    char* f=ptr-1; while(s<f)swap(*s,*f), ++s,--f;
    if(ptr>end)cout.write(_buf,ptr-_buf), ptr=_buf;
    *ptr++=endc;
} */

inline void pit(int x){printf("%d",x);}
inline void pln(ll x){printf("%I64d",x);}
template<typename ...Args>
inline void pit(int x,Args ...args){printf("%d ",x);pit(args...);}
template<typename ...Args>
inline void pln(ll x,Args ...args){printf("%I64d ",x);pit(args...);}
#endif

void JIZZ(){cout<<"";exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int a[100005];
set<int> st;
int attr[100005];
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=1;i<=n;++i){
        auto it=st.lower_bound(a[i]);
        if(it!=st.end()){
        ++it; if(it==st.end()){
            --it;
            ++attr[*it];
        }}
        st.insert(a[i]);
    }
    int mx=-1,ii=1;
    for(int i=1;i<=n;++i){
        if(attr[i]>mx && attr[i]>(i!=1)){
            mx=attr[i];
            ii=i;
        }
    }
    cout<<ii<<endl;
}


// #pragma GCC optimize("Ofast,no-stack-protector")
#pragma comment(linker,"/STACK:36777216")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>

using namespace std;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define PRF(...) printf(__VA_ARGS__)
#define MS(x,v) memset((x),(v),sizeof(x))
#define MS0(x) memset((x),0,sizeof(x))
#define PAR(x,n) for(int ___=0;___<(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define PAR1(x,n) for(int ___=1;___<=(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define PDE1(a) cout<<#a<<" = "<<(a)<<'\n'
#define PDE2(a,b) cout<<#a<<" = "<<(a)<<" , ", PDE1(b)
#define PDE3(a,b,c) cout<<#a<<" = "<<(a)<<" , ", PDE2(b,c)
#define PDE4(a,b,c,d) cout<<#a<<" = "<<(a)<<" , ", PDE3(b,c,d)
#define PDE5(a,b,c,d,e) cout<<#a<<" = "<<(a)<<" , ", PDE4(b,c,d,e)
#define PDE(...) macro_dispatcher(PDE, __VA_ARGS__)(__VA_ARGS__)
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define FIN freopen("in","r",stdin)
#define FOUT freopen("out","w",stdout)
#define DEBUG 1
#else
#define PDE(...) ;
#define PDE1(a) ;
#define PDE2(a,b) ;
#define PDE3(a,b,c) ;
#define PDE4(a,b,c,d) ;
#define PDE5(a,b,c,d,e) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define getchar gtx
#define FIN ;
#define FOUT ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>

template<typename TA,typename TB> ostream& operator<<(ostream& ostm, const pair<TA,TB> &p){ostm<<"("<<p.X<<","<<p.Y<<")";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm, const vector<T> &v){ostm<<"[ ";for(auto i:v)ostm<<i<<" ";ostm<<"]";return ostm;}
template<typename TA,typename TB> ostream& operator<<(ostream &ostm, const map<TA,TB> &mp){ostm<<"[ ";for(auto &it:mp)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const set<T> &s){ostm<<"[ ";for(auto &it:s)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const stack<T> &inp){stack<T> st=inp;ostm<<"[ ";while(!st.empty()){ostm<<st.top()<<" ";st.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const queue<T> &inp){queue<T> q=inp;ostm<<"[ ";while(!q.empty()){ostm<<q.front()<<" ";q.pop();}ostm<<"]";return ostm;}
template<typename TA,typename TB,typename TC> ostream& operator<<(ostream &ostm,const priority_queue<TA,TB,TC> &inp){priority_queue<TA,TB,TC> pq=inp;ostm<<"[ ";while(!pq.empty()){ostm<<pq.top()<<" ";pq.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const deque<T> &inp){deque<T> dq=inp;ostm<<"[ ";while(!dq.empty()){ostm<<dq.front()<<" ";dq.pop_front();}ostm<<"]";return ostm;}
// ostream& operator<<(ostream &ostm,const __int128 &val){__int128 cpy=val; stack<int> st; while(cpy)st.push(cpy%10),cpy/=10; while(st.size())ostm<<st.top(),st.pop();return ostm;}

// #define getchar gtx
// #define fread fread_unlocked
inline char gtx(){
    const int N=1048576;
    static char __buffer[N];
    static char *__p=__buffer,*__end=__buffer;
    if(__p==__end){
        if((__end=__buffer+fread(__buffer,1,N,stdin))==__buffer)return EOF;
        __p=__buffer;
    } return *__p++;
}

template<typename T>
inline bool rit(T &x){
    char c=0; bool fg=0;
    while(c=getchar(), (c<'0' && c!='-') || c>'9')if(c==EOF)return false;
    c=='-' ? (fg=1,x=0) : (x=c&15);
    while(c=getchar(), c>='0' && c<='9')x=x*10+(c&15);
    if(fg)x=-x; return true;
}
template<typename T,typename ...Args>
inline bool rit(T& x,Args& ...args){return rit(x)&&rit(args...);}

/* template<class T>void writeInt(T x, char endc = '\n'){
    static char _buf[4096],*ptr=_buf,*end=_buf+4096;
    if(x<0)*ptr++='-',x=-x; if(x==0)*ptr++='0';
    char* s=ptr;
    while(x){T t=x/10; char c=x-10*t+'0'; *ptr++=c; x=t;}
    char* f=ptr-1; while(s<f)swap(*s,*f), ++s,--f;
    if(ptr>end)cout.write(_buf,ptr-_buf), ptr=_buf;
    *ptr++=endc;
} */

inline void pit(int x){printf("%d",x);}
inline void pln(ll x){printf("%I64d",x);}
template<typename ...Args>
inline void pit(int x,Args ...args){printf("%d ",x);pit(args...);}
template<typename ...Args>
inline void pln(ll x,Args ...args){printf("%I64d ",x);pit(args...);}
#endif

void JIZZ(){cout<<"";exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int a[100005];
set<int> st;
int attr[100005];
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=1;i<=n;++i){
        auto it=st.lower_bound(a[i]);
        if(it!=st.end()){
        ++it; if(it==st.end()){
            --it;
            ++attr[*it];
        }}
        st.insert(a[i]);
    }
    int mx=-1,ii=1;
    for(int i=1;i<=n;++i){
        if(attr[i]>mx && attr[i]>1){
            mx=attr[i];
            ii=i;
        }
    }
    cout<<ii<<endl;
}


// #pragma GCC optimize("Ofast,no-stack-protector")
#pragma comment(linker,"/STACK:36777216")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>

using namespace std;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define PRF(...) printf(__VA_ARGS__)
#define MS(x,v) memset((x),(v),sizeof(x))
#define MS0(x) memset((x),0,sizeof(x))
#define PAR(x,n) for(int ___=0;___<(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define PAR1(x,n) for(int ___=1;___<=(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define PDE1(a) cout<<#a<<" = "<<(a)<<'\n'
#define PDE2(a,b) cout<<#a<<" = "<<(a)<<" , ", PDE1(b)
#define PDE3(a,b,c) cout<<#a<<" = "<<(a)<<" , ", PDE2(b,c)
#define PDE4(a,b,c,d) cout<<#a<<" = "<<(a)<<" , ", PDE3(b,c,d)
#define PDE5(a,b,c,d,e) cout<<#a<<" = "<<(a)<<" , ", PDE4(b,c,d,e)
#define PDE(...) macro_dispatcher(PDE, __VA_ARGS__)(__VA_ARGS__)
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define FIN freopen("in","r",stdin)
#define FOUT freopen("out","w",stdout)
#define DEBUG 1
#else
#define PDE(...) ;
#define PDE1(a) ;
#define PDE2(a,b) ;
#define PDE3(a,b,c) ;
#define PDE4(a,b,c,d) ;
#define PDE5(a,b,c,d,e) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define getchar gtx
#define FIN ;
#define FOUT ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>

template<typename TA,typename TB> ostream& operator<<(ostream& ostm, const pair<TA,TB> &p){ostm<<"("<<p.X<<","<<p.Y<<")";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm, const vector<T> &v){ostm<<"[ ";for(auto i:v)ostm<<i<<" ";ostm<<"]";return ostm;}
template<typename TA,typename TB> ostream& operator<<(ostream &ostm, const map<TA,TB> &mp){ostm<<"[ ";for(auto &it:mp)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const set<T> &s){ostm<<"[ ";for(auto &it:s)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const stack<T> &inp){stack<T> st=inp;ostm<<"[ ";while(!st.empty()){ostm<<st.top()<<" ";st.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const queue<T> &inp){queue<T> q=inp;ostm<<"[ ";while(!q.empty()){ostm<<q.front()<<" ";q.pop();}ostm<<"]";return ostm;}
template<typename TA,typename TB,typename TC> ostream& operator<<(ostream &ostm,const priority_queue<TA,TB,TC> &inp){priority_queue<TA,TB,TC> pq=inp;ostm<<"[ ";while(!pq.empty()){ostm<<pq.top()<<" ";pq.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const deque<T> &inp){deque<T> dq=inp;ostm<<"[ ";while(!dq.empty()){ostm<<dq.front()<<" ";dq.pop_front();}ostm<<"]";return ostm;}
// ostream& operator<<(ostream &ostm,const __int128 &val){__int128 cpy=val; stack<int> st; while(cpy)st.push(cpy%10),cpy/=10; while(st.size())ostm<<st.top(),st.pop();return ostm;}

// #define getchar gtx
// #define fread fread_unlocked
inline char gtx(){
    const int N=1048576;
    static char __buffer[N];
    static char *__p=__buffer,*__end=__buffer;
    if(__p==__end){
        if((__end=__buffer+fread(__buffer,1,N,stdin))==__buffer)return EOF;
        __p=__buffer;
    } return *__p++;
}

template<typename T>
inline bool rit(T &x){
    char c=0; bool fg=0;
    while(c=getchar(), (c<'0' && c!='-') || c>'9')if(c==EOF)return false;
    c=='-' ? (fg=1,x=0) : (x=c&15);
    while(c=getchar(), c>='0' && c<='9')x=x*10+(c&15);
    if(fg)x=-x; return true;
}
template<typename T,typename ...Args>
inline bool rit(T& x,Args& ...args){return rit(x)&&rit(args...);}

/* template<class T>void writeInt(T x, char endc = '\n'){
    static char _buf[4096],*ptr=_buf,*end=_buf+4096;
    if(x<0)*ptr++='-',x=-x; if(x==0)*ptr++='0';
    char* s=ptr;
    while(x){T t=x/10; char c=x-10*t+'0'; *ptr++=c; x=t;}
    char* f=ptr-1; while(s<f)swap(*s,*f), ++s,--f;
    if(ptr>end)cout.write(_buf,ptr-_buf), ptr=_buf;
    *ptr++=endc;
} */

inline void pit(int x){printf("%d",x);}
inline void pln(ll x){printf("%I64d",x);}
template<typename ...Args>
inline void pit(int x,Args ...args){printf("%d ",x);pit(args...);}
template<typename ...Args>
inline void pln(ll x,Args ...args){printf("%I64d ",x);pit(args...);}
#endif

void JIZZ(){cout<<"";exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int a[100005],attr[100005];
set<int> st;
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=1;i<=n;++i){
        auto it=st.lower_bound(a[i]);
        if(it!=st.end()){
        ++it; if(it==st.end()){
            --it;
            ++attr[*it];
        }}
        st.insert(a[i]);
    }
    st.clear();
    int mx=-71717171,ii=1;
    for(int i=1;i<=n;++i){
        auto it=st.lower_bound(a[i]);
        int delta=-(it==st.end() && i>1)+attr[a[i]];
        PDE(i,attr[a[i]]);
        if(delta>mx || (delta==mx && a[i]<a[ii]))mx=delta,ii=i;
        st.insert(a[i]);
    }
    cout<<a[ii]<<endl;
}


// #pragma GCC optimize("Ofast,no-stack-protector")
#pragma comment(linker,"/STACK:36777216")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>

using namespace std;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define PRF(...) printf(__VA_ARGS__)
#define MS(x,v) memset((x),(v),sizeof(x))
#define MS0(x) memset((x),0,sizeof(x))
#define PAR(x,n) for(int ___=0;___<(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define PAR1(x,n) for(int ___=1;___<=(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define PDE1(a) cout<<#a<<" = "<<(a)<<'\n'
#define PDE2(a,b) cout<<#a<<" = "<<(a)<<" , ", PDE1(b)
#define PDE3(a,b,c) cout<<#a<<" = "<<(a)<<" , ", PDE2(b,c)
#define PDE4(a,b,c,d) cout<<#a<<" = "<<(a)<<" , ", PDE3(b,c,d)
#define PDE5(a,b,c,d,e) cout<<#a<<" = "<<(a)<<" , ", PDE4(b,c,d,e)
#define PDE(...) macro_dispatcher(PDE, __VA_ARGS__)(__VA_ARGS__)
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define FIN freopen("in","r",stdin)
#define FOUT freopen("out","w",stdout)
#define DEBUG 1
#else
#define PDE(...) ;
#define PDE1(a) ;
#define PDE2(a,b) ;
#define PDE3(a,b,c) ;
#define PDE4(a,b,c,d) ;
#define PDE5(a,b,c,d,e) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define getchar gtx
#define FIN ;
#define FOUT ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>

template<typename TA,typename TB> ostream& operator<<(ostream& ostm, const pair<TA,TB> &p){ostm<<"("<<p.X<<","<<p.Y<<")";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm, const vector<T> &v){ostm<<"[ ";for(auto i:v)ostm<<i<<" ";ostm<<"]";return ostm;}
template<typename TA,typename TB> ostream& operator<<(ostream &ostm, const map<TA,TB> &mp){ostm<<"[ ";for(auto &it:mp)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const set<T> &s){ostm<<"[ ";for(auto &it:s)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const stack<T> &inp){stack<T> st=inp;ostm<<"[ ";while(!st.empty()){ostm<<st.top()<<" ";st.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const queue<T> &inp){queue<T> q=inp;ostm<<"[ ";while(!q.empty()){ostm<<q.front()<<" ";q.pop();}ostm<<"]";return ostm;}
template<typename TA,typename TB,typename TC> ostream& operator<<(ostream &ostm,const priority_queue<TA,TB,TC> &inp){priority_queue<TA,TB,TC> pq=inp;ostm<<"[ ";while(!pq.empty()){ostm<<pq.top()<<" ";pq.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const deque<T> &inp){deque<T> dq=inp;ostm<<"[ ";while(!dq.empty()){ostm<<dq.front()<<" ";dq.pop_front();}ostm<<"]";return ostm;}
// ostream& operator<<(ostream &ostm,const __int128 &val){__int128 cpy=val; stack<int> st; while(cpy)st.push(cpy%10),cpy/=10; while(st.size())ostm<<st.top(),st.pop();return ostm;}

// #define getchar gtx
// #define fread fread_unlocked
inline char gtx(){
    const int N=1048576;
    static char __buffer[N];
    static char *__p=__buffer,*__end=__buffer;
    if(__p==__end){
        if((__end=__buffer+fread(__buffer,1,N,stdin))==__buffer)return EOF;
        __p=__buffer;
    } return *__p++;
}

template<typename T>
inline bool rit(T &x){
    char c=0; bool fg=0;
    while(c=getchar(), (c<'0' && c!='-') || c>'9')if(c==EOF)return false;
    c=='-' ? (fg=1,x=0) : (x=c&15);
    while(c=getchar(), c>='0' && c<='9')x=x*10+(c&15);
    if(fg)x=-x; return true;
}
template<typename T,typename ...Args>
inline bool rit(T& x,Args& ...args){return rit(x)&&rit(args...);}

/* template<class T>void writeInt(T x, char endc = '\n'){
    static char _buf[4096],*ptr=_buf,*end=_buf+4096;
    if(x<0)*ptr++='-',x=-x; if(x==0)*ptr++='0';
    char* s=ptr;
    while(x){T t=x/10; char c=x-10*t+'0'; *ptr++=c; x=t;}
    char* f=ptr-1; while(s<f)swap(*s,*f), ++s,--f;
    if(ptr>end)cout.write(_buf,ptr-_buf), ptr=_buf;
    *ptr++=endc;
} */

inline void pit(int x){printf("%d",x);}
inline void pln(ll x){printf("%I64d",x);}
template<typename ...Args>
inline void pit(int x,Args ...args){printf("%d ",x);pit(args...);}
template<typename ...Args>
inline void pln(ll x,Args ...args){printf("%I64d ",x);pit(args...);}
#endif

void JIZZ(){cout<<"";exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int a[100005];
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=1;i<n;++i){
        if(a[i]>a[i+1])return cout<<a[i]<<endl,0;
    }
    cout<<a[1]<<endl;
}


// #pragma GCC optimize("Ofast,no-stack-protector")
#pragma comment(linker,"/STACK:36777216")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>

using namespace std;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define PRF(...) printf(__VA_ARGS__)
#define MS(x,v) memset((x),(v),sizeof(x))
#define MS0(x) memset((x),0,sizeof(x))
#define PAR(x,n) for(int ___=0;___<(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define PAR1(x,n) for(int ___=1;___<=(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define PDE1(a) cout<<#a<<" = "<<(a)<<'\n'
#define PDE2(a,b) cout<<#a<<" = "<<(a)<<" , ", PDE1(b)
#define PDE3(a,b,c) cout<<#a<<" = "<<(a)<<" , ", PDE2(b,c)
#define PDE4(a,b,c,d) cout<<#a<<" = "<<(a)<<" , ", PDE3(b,c,d)
#define PDE5(a,b,c,d,e) cout<<#a<<" = "<<(a)<<" , ", PDE4(b,c,d,e)
#define PDE(...) macro_dispatcher(PDE, __VA_ARGS__)(__VA_ARGS__)
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define FIN freopen("in","r",stdin)
#define FOUT freopen("out","w",stdout)
#define DEBUG 1
#else
#define PDE(...) ;
#define PDE1(a) ;
#define PDE2(a,b) ;
#define PDE3(a,b,c) ;
#define PDE4(a,b,c,d) ;
#define PDE5(a,b,c,d,e) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define getchar gtx
#define FIN ;
#define FOUT ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>

template<typename TA,typename TB> ostream& operator<<(ostream& ostm, const pair<TA,TB> &p){ostm<<"("<<p.X<<","<<p.Y<<")";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm, const vector<T> &v){ostm<<"[ ";for(auto i:v)ostm<<i<<" ";ostm<<"]";return ostm;}
template<typename TA,typename TB> ostream& operator<<(ostream &ostm, const map<TA,TB> &mp){ostm<<"[ ";for(auto &it:mp)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const set<T> &s){ostm<<"[ ";for(auto &it:s)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const stack<T> &inp){stack<T> st=inp;ostm<<"[ ";while(!st.empty()){ostm<<st.top()<<" ";st.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const queue<T> &inp){queue<T> q=inp;ostm<<"[ ";while(!q.empty()){ostm<<q.front()<<" ";q.pop();}ostm<<"]";return ostm;}
template<typename TA,typename TB,typename TC> ostream& operator<<(ostream &ostm,const priority_queue<TA,TB,TC> &inp){priority_queue<TA,TB,TC> pq=inp;ostm<<"[ ";while(!pq.empty()){ostm<<pq.top()<<" ";pq.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const deque<T> &inp){deque<T> dq=inp;ostm<<"[ ";while(!dq.empty()){ostm<<dq.front()<<" ";dq.pop_front();}ostm<<"]";return ostm;}
// ostream& operator<<(ostream &ostm,const __int128 &val){__int128 cpy=val; stack<int> st; while(cpy)st.push(cpy%10),cpy/=10; while(st.size())ostm<<st.top(),st.pop();return ostm;}

// #define getchar gtx
// #define fread fread_unlocked
inline char gtx(){
    const int N=1048576;
    static char __buffer[N];
    static char *__p=__buffer,*__end=__buffer;
    if(__p==__end){
        if((__end=__buffer+fread(__buffer,1,N,stdin))==__buffer)return EOF;
        __p=__buffer;
    } return *__p++;
}

template<typename T>
inline bool rit(T &x){
    char c=0; bool fg=0;
    while(c=getchar(), (c<'0' && c!='-') || c>'9')if(c==EOF)return false;
    c=='-' ? (fg=1,x=0) : (x=c&15);
    while(c=getchar(), c>='0' && c<='9')x=x*10+(c&15);
    if(fg)x=-x; return true;
}
template<typename T,typename ...Args>
inline bool rit(T& x,Args& ...args){return rit(x)&&rit(args...);}

/* template<class T>void writeInt(T x, char endc = '\n'){
    static char _buf[4096],*ptr=_buf,*end=_buf+4096;
    if(x<0)*ptr++='-',x=-x; if(x==0)*ptr++='0';
    char* s=ptr;
    while(x){T t=x/10; char c=x-10*t+'0'; *ptr++=c; x=t;}
    char* f=ptr-1; while(s<f)swap(*s,*f), ++s,--f;
    if(ptr>end)cout.write(_buf,ptr-_buf), ptr=_buf;
    *ptr++=endc;
} */

inline void pit(int x){printf("%d",x);}
inline void pln(ll x){printf("%I64d",x);}
template<typename ...Args>
inline void pit(int x,Args ...args){printf("%d ",x);pit(args...);}
template<typename ...Args>
inline void pln(ll x,Args ...args){printf("%I64d ",x);pit(args...);}
#endif

void JIZZ(){cout<<"";exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int a[100005];
set<int> st;
int attr[100005];
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=1;i<=n;++i){
        auto it=st.lower_bound(a[i]);
        if(it!=st.end()){
        ++it; if(it==st.end()){
            --it;
            ++attr[*it];
        }}
        st.insert(a[i]);
    }
    int mx=-1,ii=-1;
    for(int i=1;i<=n;++i){
        if(attr[i]>mx){
            mx=attr[i];
            ii=i;
        }
    }
    cout<<ii<<endl;
}


// #pragma GCC optimize("Ofast,no-stack-protector")
#pragma comment(linker,"/STACK:36777216")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>

using namespace std;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define PRF(...) printf(__VA_ARGS__)
#define MS(x,v) memset((x),(v),sizeof(x))
#define MS0(x) memset((x),0,sizeof(x))
#define PAR(x,n) for(int ___=0;___<(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define PAR1(x,n) for(int ___=1;___<=(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define PDE1(a) cout<<#a<<" = "<<(a)<<'\n'
#define PDE2(a,b) cout<<#a<<" = "<<(a)<<" , ", PDE1(b)
#define PDE3(a,b,c) cout<<#a<<" = "<<(a)<<" , ", PDE2(b,c)
#define PDE4(a,b,c,d) cout<<#a<<" = "<<(a)<<" , ", PDE3(b,c,d)
#define PDE5(a,b,c,d,e) cout<<#a<<" = "<<(a)<<" , ", PDE4(b,c,d,e)
#define PDE(...) macro_dispatcher(PDE, __VA_ARGS__)(__VA_ARGS__)
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define FIN freopen("in","r",stdin)
#define FOUT freopen("out","w",stdout)
#define DEBUG 1
#else
#define PDE(...) ;
#define PDE1(a) ;
#define PDE2(a,b) ;
#define PDE3(a,b,c) ;
#define PDE4(a,b,c,d) ;
#define PDE5(a,b,c,d,e) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define getchar gtx
#define FIN ;
#define FOUT ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>

template<typename TA,typename TB> ostream& operator<<(ostream& ostm, const pair<TA,TB> &p){ostm<<"("<<p.X<<","<<p.Y<<")";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm, const vector<T> &v){ostm<<"[ ";for(auto i:v)ostm<<i<<" ";ostm<<"]";return ostm;}
template<typename TA,typename TB> ostream& operator<<(ostream &ostm, const map<TA,TB> &mp){ostm<<"[ ";for(auto &it:mp)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const set<T> &s){ostm<<"[ ";for(auto &it:s)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const stack<T> &inp){stack<T> st=inp;ostm<<"[ ";while(!st.empty()){ostm<<st.top()<<" ";st.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const queue<T> &inp){queue<T> q=inp;ostm<<"[ ";while(!q.empty()){ostm<<q.front()<<" ";q.pop();}ostm<<"]";return ostm;}
template<typename TA,typename TB,typename TC> ostream& operator<<(ostream &ostm,const priority_queue<TA,TB,TC> &inp){priority_queue<TA,TB,TC> pq=inp;ostm<<"[ ";while(!pq.empty()){ostm<<pq.top()<<" ";pq.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const deque<T> &inp){deque<T> dq=inp;ostm<<"[ ";while(!dq.empty()){ostm<<dq.front()<<" ";dq.pop_front();}ostm<<"]";return ostm;}
// ostream& operator<<(ostream &ostm,const __int128 &val){__int128 cpy=val; stack<int> st; while(cpy)st.push(cpy%10),cpy/=10; while(st.size())ostm<<st.top(),st.pop();return ostm;}

// #define getchar gtx
// #define fread fread_unlocked
inline char gtx(){
    const int N=1048576;
    static char __buffer[N];
    static char *__p=__buffer,*__end=__buffer;
    if(__p==__end){
        if((__end=__buffer+fread(__buffer,1,N,stdin))==__buffer)return EOF;
        __p=__buffer;
    } return *__p++;
}

template<typename T>
inline bool rit(T &x){
    char c=0; bool fg=0;
    while(c=getchar(), (c<'0' && c!='-') || c>'9')if(c==EOF)return false;
    c=='-' ? (fg=1,x=0) : (x=c&15);
    while(c=getchar(), c>='0' && c<='9')x=x*10+(c&15);
    if(fg)x=-x; return true;
}
template<typename T,typename ...Args>
inline bool rit(T& x,Args& ...args){return rit(x)&&rit(args...);}

/* template<class T>void writeInt(T x, char endc = '\n'){
    static char _buf[4096],*ptr=_buf,*end=_buf+4096;
    if(x<0)*ptr++='-',x=-x; if(x==0)*ptr++='0';
    char* s=ptr;
    while(x){T t=x/10; char c=x-10*t+'0'; *ptr++=c; x=t;}
    char* f=ptr-1; while(s<f)swap(*s,*f), ++s,--f;
    if(ptr>end)cout.write(_buf,ptr-_buf), ptr=_buf;
    *ptr++=endc;
} */

inline void pit(int x){printf("%d",x);}
inline void pln(ll x){printf("%I64d",x);}
template<typename ...Args>
inline void pit(int x,Args ...args){printf("%d ",x);pit(args...);}
template<typename ...Args>
inline void pln(ll x,Args ...args){printf("%I64d ",x);pit(args...);}
#endif

void JIZZ(){cout<<"";exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int a[100005];
set<int> st;
int attr[100005];
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=1;i<=n;++i){
        auto it=st.lower_bound(a[i]);
        if(it!=st.end()){
        ++it; if(it==st.end()){
            --it;
            ++attr[*it];
        }}
        st.insert(a[i]);
    }
    int mx=-1,ii=1;
    for(int i=1;i<=n;++i){
        if(attr[i]>mx && attr[i]>(i==1)){
            mx=attr[i];
            ii=i;
        }
    }
    cout<<ii<<endl;
}


// #pragma GCC optimize("Ofast,no-stack-protector")
#pragma comment(linker,"/STACK:36777216")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>

using namespace std;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define PRF(...) printf(__VA_ARGS__)
#define MS(x,v) memset((x),(v),sizeof(x))
#define MS0(x) memset((x),0,sizeof(x))
#define PAR(x,n) for(int ___=0;___<(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define PAR1(x,n) for(int ___=1;___<=(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define PDE1(a) cout<<#a<<" = "<<(a)<<'\n'
#define PDE2(a,b) cout<<#a<<" = "<<(a)<<" , ", PDE1(b)
#define PDE3(a,b,c) cout<<#a<<" = "<<(a)<<" , ", PDE2(b,c)
#define PDE4(a,b,c,d) cout<<#a<<" = "<<(a)<<" , ", PDE3(b,c,d)
#define PDE5(a,b,c,d,e) cout<<#a<<" = "<<(a)<<" , ", PDE4(b,c,d,e)
#define PDE(...) macro_dispatcher(PDE, __VA_ARGS__)(__VA_ARGS__)
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define FIN freopen("in","r",stdin)
#define FOUT freopen("out","w",stdout)
#define DEBUG 1
#else
#define PDE(...) ;
#define PDE1(a) ;
#define PDE2(a,b) ;
#define PDE3(a,b,c) ;
#define PDE4(a,b,c,d) ;
#define PDE5(a,b,c,d,e) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define getchar gtx
#define FIN ;
#define FOUT ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>

template<typename TA,typename TB> ostream& operator<<(ostream& ostm, const pair<TA,TB> &p){ostm<<"("<<p.X<<","<<p.Y<<")";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm, const vector<T> &v){ostm<<"[ ";for(auto i:v)ostm<<i<<" ";ostm<<"]";return ostm;}
template<typename TA,typename TB> ostream& operator<<(ostream &ostm, const map<TA,TB> &mp){ostm<<"[ ";for(auto &it:mp)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const set<T> &s){ostm<<"[ ";for(auto &it:s)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const stack<T> &inp){stack<T> st=inp;ostm<<"[ ";while(!st.empty()){ostm<<st.top()<<" ";st.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const queue<T> &inp){queue<T> q=inp;ostm<<"[ ";while(!q.empty()){ostm<<q.front()<<" ";q.pop();}ostm<<"]";return ostm;}
template<typename TA,typename TB,typename TC> ostream& operator<<(ostream &ostm,const priority_queue<TA,TB,TC> &inp){priority_queue<TA,TB,TC> pq=inp;ostm<<"[ ";while(!pq.empty()){ostm<<pq.top()<<" ";pq.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const deque<T> &inp){deque<T> dq=inp;ostm<<"[ ";while(!dq.empty()){ostm<<dq.front()<<" ";dq.pop_front();}ostm<<"]";return ostm;}
// ostream& operator<<(ostream &ostm,const __int128 &val){__int128 cpy=val; stack<int> st; while(cpy)st.push(cpy%10),cpy/=10; while(st.size())ostm<<st.top(),st.pop();return ostm;}

// #define getchar gtx
// #define fread fread_unlocked
inline char gtx(){
    const int N=1048576;
    static char __buffer[N];
    static char *__p=__buffer,*__end=__buffer;
    if(__p==__end){
        if((__end=__buffer+fread(__buffer,1,N,stdin))==__buffer)return EOF;
        __p=__buffer;
    } return *__p++;
}

template<typename T>
inline bool rit(T &x){
    char c=0; bool fg=0;
    while(c=getchar(), (c<'0' && c!='-') || c>'9')if(c==EOF)return false;
    c=='-' ? (fg=1,x=0) : (x=c&15);
    while(c=getchar(), c>='0' && c<='9')x=x*10+(c&15);
    if(fg)x=-x; return true;
}
template<typename T,typename ...Args>
inline bool rit(T& x,Args& ...args){return rit(x)&&rit(args...);}

/* template<class T>void writeInt(T x, char endc = '\n'){
    static char _buf[4096],*ptr=_buf,*end=_buf+4096;
    if(x<0)*ptr++='-',x=-x; if(x==0)*ptr++='0';
    char* s=ptr;
    while(x){T t=x/10; char c=x-10*t+'0'; *ptr++=c; x=t;}
    char* f=ptr-1; while(s<f)swap(*s,*f), ++s,--f;
    if(ptr>end)cout.write(_buf,ptr-_buf), ptr=_buf;
    *ptr++=endc;
} */

inline void pit(int x){printf("%d",x);}
inline void pln(ll x){printf("%I64d",x);}
template<typename ...Args>
inline void pit(int x,Args ...args){printf("%d ",x);pit(args...);}
template<typename ...Args>
inline void pln(ll x,Args ...args){printf("%I64d ",x);pit(args...);}
#endif

void JIZZ(){cout<<"";exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int a[100005],attr[100005];
set<int> st;
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=1;i<=n;++i){
        auto it=st.lower_bound(a[i]);
        if(it!=st.end()){
        ++it; if(it==st.end()){
            --it;
            ++attr[*it];
        }}
        st.insert(a[i]);
    }
    st.clear();
    int mx=-71717171,ii=1;
    for(int i=1;i<=n;++i){
        auto it=st.lower_bound(a[i]);
        int delta=-(int)(it==st.end() || a[i+1]>a[i])+attr[a[i]];
        PDE(i,attr[a[i]],delta);
        if(delta>mx || (delta==mx && a[i]<a[ii]))mx=delta,ii=i;
        st.insert(a[i]);
    }
    cout<<a[ii]<<endl;
}


// #pragma GCC optimize("Ofast,no-stack-protector")
#pragma comment(linker,"/STACK:36777216")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>

using namespace std;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define PRF(...) printf(__VA_ARGS__)
#define MS(x,v) memset((x),(v),sizeof(x))
#define MS0(x) memset((x),0,sizeof(x))
#define PAR(x,n) for(int ___=0;___<(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define PAR1(x,n) for(int ___=1;___<=(n);++___)cout<<x[___]<<" ";cout<<'\n';
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define PDE1(a) cout<<#a<<" = "<<(a)<<'\n'
#define PDE2(a,b) cout<<#a<<" = "<<(a)<<" , ", PDE1(b)
#define PDE3(a,b,c) cout<<#a<<" = "<<(a)<<" , ", PDE2(b,c)
#define PDE4(a,b,c,d) cout<<#a<<" = "<<(a)<<" , ", PDE3(b,c,d)
#define PDE5(a,b,c,d,e) cout<<#a<<" = "<<(a)<<" , ", PDE4(b,c,d,e)
#define PDE(...) macro_dispatcher(PDE, __VA_ARGS__)(__VA_ARGS__)
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define FIN freopen("in","r",stdin)
#define FOUT freopen("out","w",stdout)
#define DEBUG 1
#else
#define PDE(...) ;
#define PDE1(a) ;
#define PDE2(a,b) ;
#define PDE3(a,b,c) ;
#define PDE4(a,b,c,d) ;
#define PDE5(a,b,c,d,e) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define getchar gtx
#define FIN ;
#define FOUT ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>

template<typename TA,typename TB> ostream& operator<<(ostream& ostm, const pair<TA,TB> &p){ostm<<"("<<p.X<<","<<p.Y<<")";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm, const vector<T> &v){ostm<<"[ ";for(auto i:v)ostm<<i<<" ";ostm<<"]";return ostm;}
template<typename TA,typename TB> ostream& operator<<(ostream &ostm, const map<TA,TB> &mp){ostm<<"[ ";for(auto &it:mp)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const set<T> &s){ostm<<"[ ";for(auto &it:s)ostm<<it<<" ";ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const stack<T> &inp){stack<T> st=inp;ostm<<"[ ";while(!st.empty()){ostm<<st.top()<<" ";st.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const queue<T> &inp){queue<T> q=inp;ostm<<"[ ";while(!q.empty()){ostm<<q.front()<<" ";q.pop();}ostm<<"]";return ostm;}
template<typename TA,typename TB,typename TC> ostream& operator<<(ostream &ostm,const priority_queue<TA,TB,TC> &inp){priority_queue<TA,TB,TC> pq=inp;ostm<<"[ ";while(!pq.empty()){ostm<<pq.top()<<" ";pq.pop();}ostm<<"]";return ostm;}
template<typename T> ostream& operator<<(ostream &ostm,const deque<T> &inp){deque<T> dq=inp;ostm<<"[ ";while(!dq.empty()){ostm<<dq.front()<<" ";dq.pop_front();}ostm<<"]";return ostm;}
// ostream& operator<<(ostream &ostm,const __int128 &val){__int128 cpy=val; stack<int> st; while(cpy)st.push(cpy%10),cpy/=10; while(st.size())ostm<<st.top(),st.pop();return ostm;}

// #define getchar gtx
// #define fread fread_unlocked
inline char gtx(){
    const int N=1048576;
    static char __buffer[N];
    static char *__p=__buffer,*__end=__buffer;
    if(__p==__end){
        if((__end=__buffer+fread(__buffer,1,N,stdin))==__buffer)return EOF;
        __p=__buffer;
    } return *__p++;
}

template<typename T>
inline bool rit(T &x){
    char c=0; bool fg=0;
    while(c=getchar(), (c<'0' && c!='-') || c>'9')if(c==EOF)return false;
    c=='-' ? (fg=1,x=0) : (x=c&15);
    while(c=getchar(), c>='0' && c<='9')x=x*10+(c&15);
    if(fg)x=-x; return true;
}
template<typename T,typename ...Args>
inline bool rit(T& x,Args& ...args){return rit(x)&&rit(args...);}

/* template<class T>void writeInt(T x, char endc = '\n'){
    static char _buf[4096],*ptr=_buf,*end=_buf+4096;
    if(x<0)*ptr++='-',x=-x; if(x==0)*ptr++='0';
    char* s=ptr;
    while(x){T t=x/10; char c=x-10*t+'0'; *ptr++=c; x=t;}
    char* f=ptr-1; while(s<f)swap(*s,*f), ++s,--f;
    if(ptr>end)cout.write(_buf,ptr-_buf), ptr=_buf;
    *ptr++=endc;
} */

inline void pit(int x){printf("%d",x);}
inline void pln(ll x){printf("%I64d",x);}
template<typename ...Args>
inline void pit(int x,Args ...args){printf("%d ",x);pit(args...);}
template<typename ...Args>
inline void pln(ll x,Args ...args){printf("%I64d ",x);pit(args...);}
#endif

void JIZZ(){cout<<"";exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int a[100005],attr[100005];
set<int> st;
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=1;i<=n;++i){
        auto it=st.lower_bound(a[i]);
        if(it!=st.end()){
        ++it; if(it==st.end()){
            --it;
            ++attr[*it];
        }}
        st.insert(a[i]);
    }
    st.clear();
    int mx=-71717171,ii=1;
    for(int i=1;i<=n;++i){
        auto it=st.lower_bound(a[i]);
        int delta=-(int)(it==st.end() || (i==1&&a[i+1]>a[i]))+attr[a[i]];
        PDE(i,attr[a[i]],delta);
        if(delta>mx || (delta==mx && a[i]<a[ii]))mx=delta,ii=i;
        st.insert(a[i]);
    }
    cout<<a[ii]<<endl;
}


#include <bits/stdc++.h>

#define fs first
#define sc second

using namespace std;

const int N = 1e5 + 5;

pair<int, int> sb[N];

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        int c = 0;
    //cout << 1 << endl;
        for (int j = 0; j < i && c < 2; j++) {
            if (a[j] > a[i]) {
                c++;
            }
        }
        if (c == 1) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[i]) {
                    sb[j].sc++;
                }
            }
        }
        else if (c == 0) {
            sb[i].fs++;
        }
    }
    int x = 0;
    for (int i = 0; i < n; i++) {
        if (sb[x].sc - sb[x].fs < sb[i].sc - sb[i].fs) {
            x = i;
        }
    }
    cout << a[x] << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fs first
#define sc second

using namespace std;

const int N = 1e5 + 5;

pair<int, int> sb[N];

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        int c = 0;
    //cout << 1 << endl;
        for (int j = 0; j < i && c < 2; j++) {
            if (a[j] > a[i]) {
                c++;
            }
        }
        if (c == 1) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[i]) {
                    sb[j].sc++;
                }
            }
        }
        else if (c == 0) {
            sb[i].fs++;
        }
    }
    int x = 0;
    for (int i = 0; i < n; i++) {
        if (sb[x].sc - sb[x].fs < sb[i].sc - sb[i].fs) {
            x = i;
        }
        if (sb[x].sc - sb[x].fs == sb[i].sc - sb[i].fs && a[x] > a[i]) {
            x = i;
        }
    }
    cout << a[x] << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fs first
#define sc second

using namespace std;

const int N = 1e5 + 5;

pair<int, int> sb[N];

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        int c = 0;
        if (i - a[i] > 1)
            continue;
        for (int j = 0; j < i && c < 2; j++) {
            if (a[j] > a[i]) {
                c++;
            }
        }
        if (c == 1) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[i]) {
                    sb[j].sc++;
                    break;
                }
            }
        }
        else if (c == 0) {
            sb[i].fs++;
        }
    }
    int x = 0;
    for (int i = 0; i < n; i++) {
        if (sb[x].sc - sb[x].fs < sb[i].sc - sb[i].fs) {
            x = i;
        }
        if (sb[x].sc - sb[x].fs == 0 && (sb[i].sc - sb[i].fs == 0 && sb[i].fs != 1)) {
            x = i;
        }
    }
    cout << a[x] << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int sb[N];

int main() {
    int n; cin >> n;
    vector<int> arr, b;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        if (i - x <= 1) {
            arr.push_back(x);
        }
        else {
            b.push_back(x);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            if (arr[j] >= arr[i]) {
                sb[j]++;
            }
        }
    }
    int mx = 0;
    for (int i = 0; i < n; i++) {
        if (sb[i] > sb[mx])
            mx = i;
    }
    if (b.size() == 0)
        cout << arr[mx] << endl;
    else
        cout << b[0] << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int sb[N];

int main() {
    int n; cin >> n;
    vector<int> arr, b;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        if (i - x <= 1) {
            arr.push_back(x);
        }
        else {
            b.push_back(x);
        }
    }
    n = (int)arr.size();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            if (arr[j] >= arr[i]) {
                sb[j]++;
            }
        }
    }
    int mx = 0;
    for (int i = 0; i < n; i++) {
        if (sb[i] > sb[mx])
            mx = i;
    }
    if (b.size() == 0)
        cout << arr[mx] << endl;
    else
        cout << b[0] << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int sb[N];

int main() {
    int n; cin >> n;
    vector<int> arr, b;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        if (i - x <= 1) {
            arr.push_back(x);
        }
        else {
            b.push_back(x);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            if (arr[j] >= arr[i]) {
                sb[j]++;
            }
        }
    }
    int mx = 0;
    for (int i = 0; i < n; i++) {
        if (sb[i] > sb[mx])
            mx = i;
    }
    if (b.size() == 0)
        cout << arr[mx] << endl;
    else {
        assert(0);
        cout << b[0] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define fs first
#define sc second

using namespace std;

const int N = 1e5 + 5;

pair<int, int> sb[N];

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        int c = 0;
        if (i - a[i] > 1)
            continue;
        for (int j = 0; j < i && c < 2; j++) {
            if (a[j] > a[i]) {
                c++;
            }
        }
        if (c == 1) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[i]) {
                    sb[j].sc++;
                    break;
                }
            }
        }
        else if (c == 0) {
            sb[i].fs++;
        }
    }
    int x = 0;
    for (int i = 0; i < n; i++) {
        if (sb[x].sc - sb[x].fs < sb[i].sc - sb[i].fs) {
            x = i;
        }
    }
    cout << a[x] << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int sb[N];

int main() {
    int n; cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            if (arr[j] >= arr[i]) {
                sb[j]++;
            }
        }
    }
    int mx = 0;
    for (int i = 0; i < n; i++) {
        if (sb[i] > sb[mx])
            mx = i;
    }
    cout << arr[mx] << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fs first
#define sc second

using namespace std;

const int N = 1e5 + 5;

pair<int, int> sb[N];

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        int c = 0;
        for (int j = 0; j < i && c < 2; j++) {
            if (a[j] > a[i]) {
                c++;
            }
        }
        if (c == 1) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[i]) {
                    sb[j].sc++;
                    break;
                }
            }
        }
        else if (c == 0) {
            sb[i].fs++;
        }
    }
    int x = 0;
    for (int i = 0; i < n; i++) {
        if (sb[x].sc - sb[x].fs <= sb[i].sc - sb[i].fs) {
            x = i;
        }
    }
    cout << a[x] << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fs first
#define sc second

using namespace std;

const int N = 1e5 + 5;

pair<int, int> sb[N];

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        int c = 0;
        if (i - a[i] > 1)
            continue;
        for (int j = 0; j < i && c < 2; j++) {
            if (a[j] > a[i]) {
                c++;
            }
        }
        if (c == 1) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[i]) {
                    sb[j].sc++;
                    break;
                }
            }
        }
        else if (c == 0) {
            sb[i].fs++;
        }
    }
    int x = 0;
    for (int i = 0; i < n; i++) {
        if (sb[x].sc - sb[x].fs < sb[i].sc - sb[i].fs) {
            x = i;
        }
        if (sb[x].fs == 1 && sb[i].sc - sb[i].fs == 0) {
            x = i;
        }
    }
    cout << a[x] << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fs first
#define sc second

using namespace std;

const int N = 1e5 + 5;

pair<int, int> sb[N];

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        int c = 0;
    //cout << 1 << endl;
        for (int j = 0; j < i && c < 2; j++) {
            if (a[j] > a[i]) {
                c++;
            }
        }
        if (c == 1) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[i]) {
                    sb[j].sc++;
                }
            }
        }
        else if (c == 0) {
            sb[i].fs++;
        }
    }
    int x = 0;
    for (int i = 0; i < n; i++) {
        if (sb[x].sc - sb[x].fs < sb[i].sc - sb[i].fs) {
            x = i;
        }
        if (sb[x].sc - sb[x].fs == sb[i].sc - sb[i].fs && arr[x] > arr[i]) {
            x = i;
        }
    }
    cout << a[x] << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fs first
#define sc second

using namespace std;

const int N = 1e5 + 5;

pair<int, int> sb[N];

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        int c = 0;
        for (int j = 0; j < i && c < 2; j++) {
            if (a[j] > a[i]) {
                c++;
            }
        }
        if (c == 1) {
            for (int j = 0; j < i; j++) {
                if (a[j] > a[i]) {
                    sb[j].sc++;
                    break;
                }
            }
        }
        else if (c == 0 && i > 0) {
            sb[i].fs++;
        }
    }
    int x = 0;
    for (int i = 0; i < n; i++) {
        if (sb[x].sc - sb[x].fs < sb[i].sc - sb[i].fs) {
            x = i;
        }
    }
    cout << a[x] << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;

int fre[N];

int sum(int pos){
    int ans = 0;
    while(pos > -1){
        ans += fre[pos];
        pos = ((pos + 1) & pos) - 1;
    }
}

void add(int pos, int pl){
    while(pos < N){
        fre[pos] += pl;
        pos |= pos + 1;
    }
}

int main(){
    int n;
    cin >>n;
    vector <int> f(n), a(n);
    int pos;
    for (int i=0; i<n; ++i){
        cin >>a[i];
        int now = sum(n - 1) - sum(a[i] - 1);
        add(i, 1);
        if (now == 1){
            f[pos]++;
        } else if (now == 0){
            pos = i;
        }
    }
    int ans = 0;
    for (int i=1; i<n; ++i){
        if (f[i] > f[ans]){
            ans = i;
        }
    }
    cout <<a[ans] <<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;

int fre[N];

int sum(int pos){
    int ans = 0;
    while(pos > -1){
        ans += fre[pos];
        pos = ((pos + 1) & pos) - 1;
    }
    return ans;
}

void add(int pos, int pl){
    while(pos < N){
        fre[pos] += pl;
        pos |= pos + 1;
    }
}

int main(){
    int n;
    cin >>n;
    vector <int> f(n), a(n);
    int pos;
    for (int i=0; i<n; ++i){
        cin >>a[i];
        int now = sum(n - 1) - sum(a[i] - 1);
        add(a[i] - 1, 1);
        if (now == 1){
            f[pos]++;
        } else if (now == 0){
            pos = i;
        }
    }
    int ans = 0;
    for (int i=1; i<n; ++i){
        if (f[i] > f[ans]){
            ans = i;
        } else if (f[i] == f[ans]){
            ans = ((a[i] < a[ans]) ?i:ans);
        }
    }
    cout <<a[ans] <<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;

int fre[N];

int sum(int pos){
    int ans = 0;
    while(pos > -1){
        ans += fre[pos];
        pos = ((pos + 1) & pos) - 1;
    }
}

void add(int pos, int pl){
    while(pos < N){
        fre[pos] += pl;
        pos |= pos + 1;
    }
}

int main(){
    int n;
    cin >>n;
    vector <int> f(n), a(n);
    int pos;
    for (int i=0; i<n; ++i){
        cin >>a[i];
        int now = sum(n - 1) - sum(a[i] - 1);
        add(i, 1);
        if (now == 1){
            f[pos]++;
        } else if (now == 0){
            pos = i;
        }
    }
    int ans = 0;
    for (int i=1; i<n; ++i){
        if (f[i] > f[ans]){
            ans = i;
        } else if (f[i] == f[ans]){
            ans = ((a[i] < a[ans]) ?i:ans);
        }
    }
    cout <<a[ans] <<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;

int fre[N];

int sum(int pos){
    int ans = 0;
    while(pos > -1){
        ans += fre[pos];
        pos = ((pos + 1) & pos) - 1;
    }
    return ans;
}

void add(int pos, int pl){
    while(pos < N){
        fre[pos] += pl;
        pos |= pos + 1;
    }
}

int main(){
    int n;
    cin >>n;
    vector <int> f(n), a(n);
    int pos;
    for (int i=0; i<n; ++i){
        cin >>a[i];
        int now = sum(n - 1) - sum(a[i] - 1);
        add(a[i] - 1, 1);
        if (now == 1){
            f[pos]++;
        } else if (now == 0){
            pos = i;
        }
    }
    int ans = 0;
    for (int i=1; i<n; ++i){
        if (f[i] > f[ans]){
            ans = i;
        } else if (f[i] == f[ans] || f[ans] == 1){
            ans = ((a[i] < a[ans]) ?i:ans);
        }
    }
    cout <<a[ans] <<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;

int fre[N];

int sum(int pos){
    int ans = 0;
    while(pos > -1){
        ans += fre[pos];
        pos = ((pos + 1) & pos) - 1;
    }
    return ans;
}

void add(int pos, int pl){
    while(pos < N){
        fre[pos] += pl;
        pos |= pos + 1;
    }
}

int main(){
    int n;
    cin >>n;
    vector <int> f(n), a(n), greater(n);
    int pos;
    for (int i=0; i<n; ++i){
        cin >>a[i];
        greater[i] = sum(n - 1) - sum(a[i] - 1);
//        cout <<greater[i] <<' ';
        add(a[i] - 1, 1);
        if (greater[i] == 1){
            f[pos]++;
        } else if (greater[i] == 0){
            pos = i;
        }
    }
    cout <<'\n';
    int ans = 0;
    for (int i=1; i<n; ++i){
//        cout <<ans <<' ' <<f[ans] <<'\n';
        if (f[i] > f[ans]){
            ans = i;
        } else if (greater[ans] == 0 && f[ans] == 0){
            ans = i;
        } else {
            ans = (a[i] < a[ans] ?i:ans);
        }
    }
    cout <<a[ans] <<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;

int fre[N];

int sum(int pos){
    int ans = 0;
    while(pos > -1){
        ans += fre[pos];
        pos = ((pos + 1) & pos) - 1;
    }
    return ans;
}

void add(int pos, int pl){
    while(pos < N){
        fre[pos] += pl;
        pos |= pos + 1;
    }
}

int main(){
    int n;
    cin >>n;
    vector <int> f(n), a(n), greater(n);
    int pos;
    for (int i=0; i<n; ++i){
        cin >>a[i];
        greater[i] = sum(n - 1) - sum(a[i] - 1);
    //    cout <<greater[i] <<' ';
        add(a[i] - 1, 1);
        if (greater[i] == 1){
            f[pos]++;
        } else if (greater[i] == 0){
            pos = i;
        }
    }
    // cout <<'\n';
    int ans = 0;
    for (int i=1; i<n; ++i){
    //    cout <<greater[ans] <<' ' <<f[ans] <<'\n';
        if (f[i] > f[ans]){
            ans = i;
        } else if (f[i] == f[ans]){
        //    cout <<"kai\n";
            if (greater[ans] == 0 && f[ans] == 0 && greater[i] != 0){
                ans = i;
            } else {
                ans = (a[i] < a[ans] ?i:ans);
            }
        }
    }
    cout <<a[ans] <<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;

int fre[N];

int sum(int pos){
    int ans = 0;
    while(pos > -1){
        ans += fre[pos];
        pos = ((pos + 1) & pos) - 1;
    }
    return ans;
}

void add(int pos, int pl){
    while(pos < N){
        fre[pos] += pl;
        pos |= pos + 1;
    }
}

int main(){
    int n;
    cin >>n;
    vector <int> f(n), a(n), greater(n);
    int pos;
    for (int i=0; i<n; ++i){
        cin >>a[i];
        greater[i] = sum(n - 1) - sum(a[i] - 1);
        add(a[i] - 1, 1);
        if (greater[i] == 1){
            f[pos]++;
        } else if (greater[i] == 0){
            pos = i;
        }
    }
    int ans = 0;
    for (int i=1; i<n; ++i){
        if (f[i] > f[ans]){
            ans = i;
        } else if (f[i] == f[ans]){
            ans = (a[i] < a[ans] ?i:ans);
        }
    }
    if (f[ans] > 1){
        cout <<a[ans] <<'\n';
    } else {
        int ans1 = -1;
        for (int i=0; i<n; ++i){
            if (greater[i] > 0){
                if (ans1 == -1){
                    ans1 = i;
                } else {
                    ans1 = (a[i] < a[ans1] ?i:ans1);
                }
            }
        }
        if (ans1 == -1) {
            cout <<a[ans] <<'\n';
        } else {
            cout <<a[ans1] <<'\n';
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1.0), EPS = 1e-9;
const int MX=1*1e5+10;
int N, M, k;
int arr[MX];
int p[MX];
int sz[MX];
int f(int x)
{
    if(x == p[x]) return x;
    return p[x]=f(p[x]);
}
void un(int x, int y)
{

    x=f(x);
    y=f(y);
    if(x == y) return;
    sz[y]+=sz[x];
    p[x]=y;
}
multiset<int> ms;
int want[MX];
int main()
{
    scanf("%d", &N);

    for(int i=1; i<N+1; i++)
    {
        scanf("%d", &arr[i]);
        p[i]=-1;
        sz[i]=1;
    }
    if(N == 1)
    {
        cout<<1;
        return 0;
    }
    for(int i=1; i<N+1; i++)
    {
        if(ms.size() == 0)
        {
            ms.insert(arr[i]);

        }
        else
        {

            int b=0;
            multiset<int> ::iterator it=ms.end();
            it--;
            int ff=-1, ss=-1;
            ff=*it;
            if(it != ms.begin()) it--, ss=*it;
            if(arr[i] > ff)
            {
                ms.insert(arr[i]);
                continue;
            }
            if(arr[i] > ss)
            {
                ms.insert(arr[i]);
                want[i]=ff;
            }
            ms.insert(arr[i]);
            continue;
        }
    }

    int who=-1, mx=0;
    map<int, int> mpp;

    for(int i=1; i<=N; i++)
    {
     ///   cout<<want[i]<<" ";
        if(want[i])
        {
            mpp[want[i]]++;
        }
    }
    map<int, int> ::iterator itt=mpp.begin();
    while(itt != mpp.end())
    {
        if(itt->S > mx)
        {
            who=itt->F;
            mx=itt->S;
        }
        itt++;
    }
    if(who == -1) who=arr[0];
    cout<<who;
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1.0), EPS = 1e-9;
const int MX=1*1e5+10;
int N, M, k;
int arr[MX];
int p[MX];
int sz[MX];
int f(int x)
{
    if(x == p[x]) return x;
    return p[x]=f(p[x]);
}
void un(int x, int y)
{
    x=f(x);
    y=f(y);
    if(x == y) return;
    sz[y]+=sz[x];
    p[x]=y;
}
multiset<int> ms;
int main()
{
    scanf("%d", &N);

    for(int i=1; i<N+1; i++)
    {
        scanf("%d", &arr[i]);
        p[i]=-1;
        sz[i]=1;
    }
    if(N == 1)
    {
        cout<<1;
        return 0;
    }
    for(int i=0; i<N+1; i++)
    {
        if(ms.size() == 0)
        {
            ms.insert(arr[i]);

        }
        else
        {

            int b=0;
            multiset<int> ::iterator it=ms.end();
            it--;
            int ff=-1, ss=-1;
            ff=*it;
            if(it != ms.begin()) it--, ss=*it;
            if(arr[i] > ff)
            {
                ms.insert(arr[i]);
                continue;
            }
            if(arr[i] > ss)
            {
                ms.insert(arr[i]);
                p[i]=i;
                p[ff]=ff;
                un(i,ff);
            }
            ms.insert(arr[i]);
            continue;
        }
    }
    int who=-1, mx=0;
    for(int i=1; i<=N; i++)
    {
        if(p[i] == -1) continue;
        if(sz[f(i)] > mx)
        {
            mx=sz[f(i)];
            who=f(i);
        }
    }
    cout<<who;
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1.0), EPS = 1e-9;
const int MX=1*1e5+10;
int N, M, k;
int arr[MX];
int p[MX];
int sz[MX];
int f(int x)
{
    if(x == p[x]) return x;
    return p[x]=f(p[x]);
}
void un(int x, int y)
{
    x=f(x);
    y=f(y);
    if(x == y) return;
    sz[y]+=sz[x];
    p[x]=y;
}
multiset<int> ms;
int main()
{
    scanf("%d", &N);

    for(int i=1; i<N+1; i++)
    {
        scanf("%d", &arr[i]);
        p[i]=-1;
        sz[i]=1;
    }
    if(N == 1)
    {
        cout<<1;
        return 0;
    }
    for(int i=1; i<N+1; i++)
    {
        if(ms.size() == 0)
        {
            ms.insert(arr[i]);

        }
        else
        {

            int b=0;
            multiset<int> ::iterator it=ms.end();
            it--;
            int ff=-1, ss=-1;
            ff=*it;
            if(it != ms.begin()) it--, ss=*it;
            if(arr[i] > ff)
            {
                ms.insert(arr[i]);
                continue;
            }
            if(arr[i] > ss)
            {
                ms.insert(arr[i]);
                p[i]=i;
                p[ff]=ff;
                un(i,ff);
            }
            ms.insert(arr[i]);
            continue;
        }
    }
    int who=-1, mx=0;
    for(int i=1; i<=N; i++)
    {
        if(p[i] == -1) continue;
        if(sz[f(i)] > mx)
        {
            mx=sz[f(i)];
            who=f(i);
        }
    }
    cout<<who;
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1.0), EPS = 1e-9;
const int MX=1*1e5+10;
int N, M, k;
int arr[MX];
int p[MX];
int sz[MX];
int f(int x)
{
    if(x == p[x]) return x;
    return p[x]=f(p[x]);
}
void un(int x, int y)
{

    x=f(x);
    y=f(y);
    if(x == y) return;
    sz[y]+=sz[x];
    p[x]=y;
}
multiset<int> ms;
int want[MX];
int main()
{
    scanf("%d", &N);

    for(int i=1; i<N+1; i++)
    {
        scanf("%d", &arr[i]);
        p[i]=-1;
        sz[i]=1;
    }
    if(N == 1)
    {
        cout<<1;
        return 0;
    }
    for(int i=1; i<N+1; i++)
    {
        if(ms.size() == 0)
        {
            ms.insert(arr[i]);

        }
        else
        {

            int b=0;
            multiset<int> ::iterator it=ms.end();
            it--;
            int ff=-1, ss=-1;
            ff=*it;
            if(it != ms.begin()) it--, ss=*it;
            if(arr[i] > ff)
            {
                ms.insert(arr[i]);
                continue;
            }
            if(arr[i] > ss)
            {
                ms.insert(arr[i]);
                want[i]=ff;
            }
            ms.insert(arr[i]);
            continue;
        }
    }

    int who=-1, mx=0;
    map<int, int> mpp;

    for(int i=1; i<=N; i++)
    {
     ///   cout<<want[i]<<" ";
        if(want[i])
        {
            mpp[want[i]]++;
        }
    }
    map<int, int> ::iterator itt=mpp.begin();
    while(itt != mpp.end())
    {
        if(itt->S > mx)
        {
            who=itt->F;
            mx=itt->S;
        }
        itt++;
    }
    if(who == -1) who=1;
    cout<<who;
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1.0), EPS = 1e-9;
const int MX=1*1e5+10;
int N, M, k;
int arr[MX];
int p[MX];
int sz[MX];
int f(int x)
{
    if(x == p[x]) return x;
    return p[x]=f(p[x]);
}
void un(int x, int y)
{

    x=f(x);
    y=f(y);
    if(x == y) return;
    sz[y]+=sz[x];
    p[x]=y;
}
multiset<int> ms;
int want[MX];
map<int, int> mpp;
int main()
{
    scanf("%d", &N);

    for(int i=1; i<=N; i++)
    {
        scanf("%d", &arr[i]);
        p[i]=-1;
        sz[i]=1;
    }
    if(N == 1)
    {
        cout<<1;
        return 0;
    }
    int who=-1;
    for(int i=1; i<=N; i++)
    {
        if(ms.size() == 0)
        {
            ms.insert(arr[i]);

        }
        else
        {

            multiset<int> ::iterator it=ms.end();
            it--;
            int ff=-1, ss=-1;
            ff=*it;
            if(it != ms.begin())
            {
                it--;
                ss=*it;
            }
            if(arr[i] > ff)
            {
                ms.insert(arr[i]);
                continue;
            }
            if(arr[i] > ss)
            {
                ms.insert(arr[i]);
                want[i]=ff;
                continue;
            }
            if(ss != -1)
                who=arr[i];
            ms.insert(arr[i]);
            continue;
        }
    }

    int mx=0;

    for(int i=1; i<=N; i++)
    {
        ///   cout<<want[i]<<" ";
        if(want[i])
        {
            mpp[want[i]]++;
        }
    }
    map<int, int> ::iterator itt=mpp.begin();
    while(itt != mpp.end())
    {
        if(itt->S >= mx)
        {
            who=itt->F;
            mx=itt->S;
        }
        itt++;
    }
    if(who == -1) who=arr[1];
    cout<<who;
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1.0), EPS = 1e-9;
const int MX=1*1e5+10;
int N, M, k;
int arr[MX];
int p[MX];
int sz[MX];
int f(int x)
{
    if(x == p[x]) return x;
    return p[x]=f(p[x]);
}
void un(int x, int y)
{

    x=f(x);
    y=f(y);
    if(x == y) return;
    sz[y]+=sz[x];
    p[x]=y;
}
multiset<int> ms;
int want[MX];
map<int, int> mpp;
int main()
{
    scanf("%d", &N);

    for(int i=1; i<=N; i++)
    {
        scanf("%d", &arr[i]);
        p[i]=-1;
        sz[i]=1;
    }
    if(N == 1)
    {
        cout<<1;
        return 0;
    }
    int who=1e9;
    for(int i=1; i<=N; i++)
    {
        if(ms.size() == 0)
        {
            ms.insert(arr[i]);

        }
        else
        {

            multiset<int> ::iterator it=ms.end();
            it--;
            int ff=-1, ss=-1;
            ff=*it;
            if(it != ms.begin())
            {
                it--;
                ss=*it;
            }
            if(arr[i] > ff)
            {
                ms.insert(arr[i]);
                continue;
            }
            if(arr[i] > ss)
            {
                ms.insert(arr[i]);
                want[i]=ff;
                continue;
            }
            if(ss != -1)
                {
                    who=min(who, arr[i]);
                }
            ms.insert(arr[i]);
            continue;
        }
    }

    int mx=0;

    for(int i=1; i<=N; i++)
    {
        ///   cout<<want[i]<<" ";
        if(want[i])
        {
            mpp[want[i]]++;
        }
    }
    map<int, int> ::iterator itt=mpp.begin();
    vector<int> v;
    while(itt != mpp.end())
    {
        if(itt->S >= mx)
        {
            if(itt->S == mx)
                v.pb(itt->F);
            else {
                v.clear();
                 v.pb(itt->F);
            }
            mx=itt->S;
        }
        itt++;
    }
    for(int i=0;i<v.size();i++)
    {
        who=min(who, v[i]);
    }
    if(who == 1e9) who=arr[1];
    cout<<who;
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1.0), EPS = 1e-9;
const int MX=1*1e5+10;
int N, M, k;
int arr[MX];
int p[MX];
int sz[MX];
int f(int x)
{
    if(x == p[x]) return x;
    return p[x]=f(p[x]);
}
void un(int x, int y)
{

    x=f(x);
    y=f(y);
    if(x == y) return;
    sz[y]+=sz[x];
    p[x]=y;
}
multiset<int> ms;
int want[MX];
map<int, int> mpp;
int main()
{
    scanf("%d", &N);
    int mn=1e9;

    for(int i=1; i<=N; i++)
    {
        scanf("%d", &arr[i]);
        p[i]=-1;
        sz[i]=1;
        mn=min(mn, arr[i]);
    }
    if(N == 1)
    {
        cout<<1;
        return 0;
    }
    int who=1e9;
    for(int i=1; i<=N; i++)
    {
        if(ms.size() == 0)
        {
            ms.insert(arr[i]);

        }
        else
        {

            multiset<int> ::iterator it=ms.end();
            it--;
            int ff=-1, ss=-1;
            ff=*it;
            if(it != ms.begin())
            {
                it--;
                ss=*it;
            }
            if(arr[i] > ff)
            {
                ms.insert(arr[i]);
                continue;
            }
            if(arr[i] > ss)
            {
                ms.insert(arr[i]);
                want[i]=ff;
                continue;
            }
            if(ss != -1)
            {
                who=min(who, arr[i]);
            }
            ms.insert(arr[i]);
            continue;
        }
    }

    int mx=0;

    for(int i=1; i<=N; i++)
    {
        ///   cout<<want[i]<<" ";
        if(want[i])
        {
            mpp[want[i]]++;
        }
    }
    map<int, int> ::iterator itt=mpp.begin();
    vector<int> v;
    while(itt != mpp.end())
    {
        if(itt->S >= mx)
        {
            if(itt->S == mx)
                v.pb(itt->F);
            else
            {
                v.clear();
                v.pb(itt->F);
            }
            mx=itt->S;
        }
        itt++;
    }
    int n=who;
    who=1e9;
    for(int i=0; i<v.size(); i++)
    {
        who=min(who, v[i]);
    }
    if(who == 1e9) who=n;
    if(who == 1e9) who=mn;
    cout<<who;
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1.0), EPS = 1e-9;
const int MX=1*1e5+10;
int N, M, k;
int arr[MX];
int p[MX];
int sz[MX];
int f(int x)
{
    if(x == p[x]) return x;
    return p[x]=f(p[x]);
}
void un(int x, int y)
{

    x=f(x);
    y=f(y);
    if(x == y) return;
    sz[y]+=sz[x];
    p[x]=y;
}
multiset<int> ms;
int want[MX];
int main()
{
    scanf("%d", &N);

    for(int i=1; i<N+1; i++)
    {
        scanf("%d", &arr[i]);
        p[i]=-1;
        sz[i]=1;
    }
    if(N == 1)
    {
        cout<<1;
        return 0;
    }
    for(int i=1; i<N+1; i++)
    {
        if(ms.size() == 0)
        {
            ms.insert(arr[i]);

        }
        else
        {

            int b=0;
            multiset<int> ::iterator it=ms.end();
            it--;
            int ff=-1, ss=-1;
            ff=*it;
            if(it != ms.begin()) it--, ss=*it;
            if(arr[i] > ff)
            {
                ms.insert(arr[i]);
                continue;
            }
            if(arr[i] > ss)
            {
                ms.insert(arr[i]);
                want[i]=ff;
            }
            ms.insert(arr[i]);
            continue;
        }
    }

    int who=-1, mx=0;
    map<int, int> mpp;

    for(int i=1; i<=N; i++)
    {
     ///   cout<<want[i]<<" ";
        if(want[i])
        {
            mpp[want[i]]++;
        }
    }
    map<int, int> ::iterator itt=mpp.begin();
    while(itt != mpp.end())
    {
        if(itt->S > mx)
        {
            who=itt->F;
            mx=itt->S;
        }
        itt++;
    }
    cout<<who;
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const double PI = acos(-1.0), EPS = 1e-9;
const int MX=1*1e5+10;
int N, M, k;
int arr[MX];
int ableD[MX], want[MX], forW[MX], backW[MX];
multiset<int> ms;
multiset<int>::iterator it;
int main()
{
    scanf("%d", &N);
    for(int i=1; i<=N; i++)
    {
        scanf("%d", &arr[i]);
    }
    for(int i=1; i<=N; i++)
    {
        if(ms.size() == 0)
        {
            ms.insert(arr[i]);
        }
        else
        {
            int f, s=-1;
            it=ms.end(); it--;
            f=*it;
            if(it != ms.begin())
            {
                it--;
                s=*it;
            }
            ms.insert(arr[i]);
            if(arr[i] > f)
            {
                continue;
            }
            if(arr[i] > s)
            {
                want[f]++;
                forW[arr[i]]=f;
                backW[f]=arr[i];
                continue;
            }
            ableD[arr[i]]++;
        }
    }
    int mx=0, who=1e9;
    for(int i=1;i<=N;i++)
    {
     //   cout<<ableD[i]<<" ";
        if(want[i] > mx)
        {
            who=i;
            mx=want[i];
        }
    }/// cout<<mx<<"\n";
    if(mx == 1)
    {
        for(int i=1;i<=N;i++)
        {
            if(want[i])
            {
                ableD[i]++;
                ableD[backW[i]]++;
            }
        }
        for(int i=1;i<=N;i++)
        {
            if(ableD[i])
            {
                who=min(i, who);
                break;
            }
        }
    }
    if(who == 1e9) for(int i=1;i<=N;i++) if(ableD[i]) who=min(who, i);
    if(who == 1e9) who=1;
    cout<<who;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> edge[100001];
vector<int> clique[100001], work[100001];
int deg[100001], vis[100001], ans[100001], cnt;
int e[100001];
void check(int x) {
	++cnt;
	for (int i : edge[x])
		if (!vis[i]) clique[cnt].push_back(i);
	clique[cnt].push_back(x);
	for (int i : clique[cnt]) work[i].push_back(cnt);
}
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n, m, k;
		cin >> n >> m >> k;
		for (int i = 1; i <= m; i++) {
			int u, v;
			cin >> u >> v;
			edge[u].push_back(v), edge[v].push_back(u);
			++deg[u], ++deg[v];
		}
		queue<int> q;
		for (int i = 1; i <= n; i++)
			if (deg[i] < k-1) q.push(i);
		set<int> s0;
		for (int i = 1; i <= n; i++) s0.insert(i);
		bool tmp = 0;
		while (!tmp && s0.size()) {
			while (q.size()) {
				int u = q.front();
				s0.erase(u);
				q.pop(), vis[u] = 0;
				for (int i : edge[u])
					if (!vis[i]) {
						--deg[i];
						if (deg[i] == k-2) q.push(i);
					}
			}
			tmp = 1;
			for (int i : s0)
				if (deg[i] == k-1) {
					tmp = 0, check(i), q.push(i);
					break;
				}
		}
		bool flag = 0;
		if (s0.size()) {
			flag = 1;
			cout << 1 << ' ' << s0.size() << endl;
			for (int i : s0) cout << i << ' ';
			cout << endl;
		}
		else {
			for (int i = 1; i <= n; i++) {
				for (int j : edge[i]) e[j] = 1;
				for (int j : work[i])
					for (int x : clique[j])
						if (e[x]) ++ans[j];
				for (int j : edge[i]) e[j] = 0;
			}
			for (int i = 1; i <= cnt; i++)
				if (ans[i] == 1ll*k*(k-1)) {
					cout << 2 << endl;
					for (int j : clique[i]) cout << j << ' ';
					cout << endl, flag = 1;
					break;
				}
			if (!flag) puts("-1");
		}
		for (int i = 1; i <= n; i++) edge[i].clear(), deg[i] = vis[i] = 0, work[i].clear();
		for (int i = 1; i <= cnt; i++) clique[i].clear(), ans[i] = 0;
		cnt = 0;
	}
}


#include<bits/stdc++.h>
using namespace std;
vector<int> edge[100001];
vector<int> clique[100001], work[100001];
int deg[100001], vis[100001], ans[100001], cnt;
int e[100001];
void check(int x) {
	++cnt;
	for (int i : edge[x])
		if (!vis[i]) clique[cnt].push_back(i);
	clique[cnt].push_back(x);
	for (int i : clique[cnt]) work[i].push_back(cnt);
}
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n, m, k;
		cin >> n >> m >> k;
		for (int i = 1; i <= m; i++) {
			int u, v;
			cin >> u >> v;
			edge[u].push_back(v), edge[v].push_back(u);
			++deg[u], ++deg[v];
		}
		queue<int> q;
		for (int i = 1; i <= n; i++)
			if (deg[i] < k-1) q.push(i);
		set<int> s0;
		for (int i = 1; i <= n; i++) s0.insert(i);
		bool tmp = 0;
		while (!tmp && s0.size()) {
			while (q.size()) {
				int u = q.front();
				s0.erase(u);
				q.pop(), vis[u] = 1;
				for (int i : edge[u])
					if (!vis[i]) {
						--deg[i];
						if (deg[i] == k-2) q.push(i);
					}
			}
			tmp = 1;
			for (int i : s0)
				if (deg[i] == k-1) {
					tmp = 0, check(i), q.push(i);
					break;
				}
		}
		bool flag = 0;
		if (s0.size()) {
			flag = 1;
			cout << 1 << ' ' << s0.size() << endl;
			for (int i : s0) cout << i << ' ';
			cout << endl;
		}
		else {
			for (int i = 1; i <= n; i++) {
				for (int j : edge[i]) e[j] = 1;
				for (int j : work[i])
					for (int x : clique[j])
						if (e[x]) ++ans[j];
				for (int j : edge[i]) e[j] = 0;
			}
			for (int i = 1; i <= cnt; i++)
				if (ans[i] == 1ll*k*(k-1)) {
					cout << 2 << endl;
					for (int j : clique[i]) cout << j << ' ';
					cout << endl, flag = 1;
					break;
				}
			if (!flag) puts("-1");
		}
		for (int i = 1; i <= n; i++) edge[i].clear(), deg[i] = vis[i] = 0, work[i].clear();
		for (int i = 1; i <= cnt; i++) clique[i].clear(), ans[i] = 0;
		cnt = 0;
	}
}


#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;

const int N = 1e5+2;
const int M = 350;

int n,m,cnt,t,r,k,deg[N];
bool cli[N],nei[N];
vector<int> g[N],cnd[N],w[N];
queue<int> q;

void init(){
  for (int i=1;i<=n;++i){
    g[i].clear();w[i].clear();
    deg[i] = 0;
  }
}

bool step1(){
  cnt = n;
  r = 0;
  for (int i=1;i<=n;++i)
    if (deg[i]<k) q.push(i);
  while (!q.empty()){
    int u = q.front(); q.pop();
    cnt--;
    if (deg[u]==k-1){
      cnd[++r].clear();
      cnd[r].push_back(u);
      w[u].push_back(r);
      for (int i=0;i<g[u].size();++i){
        cnd[r].push_back(g[u][i]);
        w[g[u][i]].push_back(r);
      }
    }
    for (int i=0;i<g[u].size();++i){
      deg[g[u][i]]--;
      if (deg[g[u][i]]==k-1) q.push(g[u][i]);
    }
  }
  if (cnt>0){
    printf("1 %d\n", cnt);
    for (int i=1;i<=n;++i)
      if (deg[i]>=k) printf("%d ", i);
    printf("\n");
    return 1;
  }
  return 0;
}

bool step2(){ // 判断是否存在完全子图
  memset(nei,0,sizeof(nei));
  memset(cli,0,sizeof(cli));
  for (int i=1;i<=n;++i) if (w[i].size()){
    nei[i] = 1;
    for (int j=0;j<g[i].size();++j)
      nei[g[i][j]] = 1;
    for (int j=0;j<w[i].size();++j) if (!cli[w[i][j]]){
      int x = w[i][j];
      for (int l=0;l<cnd[x].size();++l)
        if (!nei[cnd[x][l]]){
          cli[x] = 1;
        }
    }
    for (int j=0;j<g[i].size();++j)
      nei[g[i][j]] = 0;
    nei[i] = 0;
  }
  for (int i=1;i<=r;++i)
    if (!cli[i]){
      printf("2\n");
      for (int j=0;j<cnd[i].size();++j)
        printf("%d ", cnd[i][j]);
      printf("\n");
      return true;
    }
  return false;
}

int main(){
	scanf("%d",&t);
  while (t--){
    scanf("%d%d%d",&n,&m,&k);
    init();
    int x,y;
    for (int i=1;i<=m;++i){
      scanf("%d%d",&x,&y);
      deg[x]++;deg[y]++;
      g[x].push_back(y);g[y].push_back(x);
    }
    if (k>2ll*m){
      printf("-1\n");
      continue;
    }
    if (step1()) continue;
    if (step2()) continue;
    printf("-1\n");
  }
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;

const int N = 1e5+2;
const int M = 350;

int n,m,cnt,t,r,k,deg[N];
bool cli[N],nei[N];
vector<int> g[N],cnd[N],w[N];
queue<int> q;

void init(){
  for (int i=1;i<=n;++i){
    g[i].clear();w[i].clear();
    deg[i] = 0;
  }
}

bool step1(){
  cnt = n;
  r = 0;
  for (int i=1;i<=n;++i)
    if (deg[i]<k) q.push(i);
  while (!q.empty()){
    int u = q.front(); q.pop();
    cnt--;
    if (deg[u]==k-1){
      cnd[++r].clear();
      cnd[r].push_back(u);
      w[u].push_back(r);
      for (int i=0;i<g[u].size();++i){
        cnd[r].push_back(g[u][i]);
        w[g[u][i]].push_back(r);
      }
    }
    for (int i=0;i<g[u].size();++i){
      deg[g[u][i]]--;
      if (deg[g[u][i]]==k-1) q.push(g[u][i]);
    }
  }
  if (cnt>0){
    printf("1 %d\n", cnt);
    for (int i=1;i<=n;++i)
      if (deg[i]>=k) printf("%d ", i);
    printf("\n");
    return 1;
  }
  return 0;
}

bool step2(){ // 判断是否存在完全子图
  memset(nei,0,sizeof(nei));
  memset(cli,0,sizeof(cli));
  for (int i=1;i<=n;++i) if (w[i].size()){
    nei[i] = 1;
    for (int j=0;j<g[i].size();++j)
      nei[g[i][j]] = 1;
    for (int j=0;j<w[i].size();++j) if (!cli[w[i][j]]){
      int x = w[i][j];
      for (int l=0;l<cnd[x].size();++l)
        if (!nei[cnd[x][l]]){
          cli[x] = 1;
        }
    }
    for (int j=0;j<g[i].size();++j)
      nei[g[i][j]] = 0;
    nei[i] = 0;
  }
  for (int i=1;i<=r;++i)
    if (!cli[i]){
      printf("2\n");
      for (int j=0;j<cnd[i].size();++j)
        printf("%d ", cnd[i][j]);
      printf("\n");
      return true;
    }
  return false;
}

int main(){
	scanf("%d",&t);
  while (t--){
    scanf("%d%d%d",&n,&m,&k);
    init();
    int x,y;
    for (int i=1;i<=m;++i){
      scanf("%d%d",&x,&y);
      deg[x]++;deg[y]++;
      g[x].push_back(y);g[y].push_back(x);
    }
    if (1ll*k*(k-1)>2ll*m){
      printf("-1\n");
      continue;
    }
    if (step1()) continue;
    if (step2()) continue;
    printf("-1\n");
  }
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;

const int N = 1e5+2;

int n,m,cnt,t,k,deg[N],w[N];
bool del[N],tag[N],nei[N];
vector<int> g[N],v[N];
queue<int> q;

void init(){
  for (int i=1;i<=n;++i){
    g[i].clear();
    deg[i] = 0;
    tag[i] = 0;
    del[i] = 0;
  }
}

bool step1(){
  cnt = n;
  for (int i=1;i<=n;++i)
    if (deg[i]<k) q.push(i);
  while (!q.empty()){
    int u = q.front(); q.pop();
    del[u] = 1;
    cnt--;
    if (deg[u]==k-1){
      tag[u] = 1; v[u].clear();
      for (int i=0;i<g[u].size();++i)
        if (!del[g[u][i]]) v[u].push_back(g[u][i]);
    }
    for (int i=0;i<g[u].size();++i){
      deg[g[u][i]]--;
      if (deg[g[u][i]]==k-1) q.push(g[u][i]);
    }
  }
  if (cnt>0){
    printf("1 %d\n", cnt);
    for (int i=1;i<=n;++i)
      if (deg[i]>=k) printf("%d ", i);
    printf("\n");
    return 1;
  }
  return 0;
}

bool step2(){ // 判断是否存在完全子图
  for (int i=1;i<=n;++i) if (tag[i]) {
    nei[i] = 1;
    for (int j=0;j<v[i].size();++j)
      nei[v[i][j]] = 1;
    bool ok = true;
    for (int j=0;j<v[i].size();++j){
      int u = v[i][j], cnt = 0;
      for (int l=0;l<g[u].size();++l){
        if (nei[g[u][l]]) cnt++;
      }
      if (cnt<k-1) {
        ok = false;
        break;
      }
    }
    nei[i] = 0;
    for (int j=0;j<v[i].size();++j)
      nei[v[i][j]] = 0;
    if (ok) {
      printf("2\n");
      for (int j=0;j<v[i].size();++j)
        printf("%d ", v[i][j]);
      printf("%d\n", i);
      return true;
    }
  }
  return false;
}

int main(){
	scanf("%d",&t);
  while (t--){
    scanf("%d%d%d",&n,&m,&k);
    init();
    int x,y;
    for (int i=1;i<=m;++i){
      scanf("%d%d",&x,&y);
      deg[x]++;deg[y]++;
      g[x].push_back(y);g[y].push_back(x);
    }
    if (k>2ll*m){
      printf("-1\n");
      continue;
    }
    if (step1()) continue;
    if (step2()) continue;
    printf("-1\n");
  }
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;

const int N = 1e5+2;

int n,m,cnt,t,k,deg[N],w[N];
bool del[N],tag[N],nei[N];
vector<int> g[N],v[N];
queue<int> q;

void init(){
  for (int i=1;i<=n;++i){
    g[i].clear();
    deg[i] = 0;
    tag[i] = 0;
    del[i] = 0;
  }
}

bool step1(){
  cnt = n;
  for (int i=1;i<=n;++i)
    if (deg[i]<k) q.push(i);
  while (!q.empty()){
    int u = q.front(); q.pop();
    del[u] = 1;
    cnt--;
    if (deg[u]==k-1){
      tag[u] = 1; v[u].clear();
      for (int i=0;i<g[u].size();++i)
        if (!del[g[u][i]]) v[u].push_back(g[u][i]);
    }
    for (int i=0;i<g[u].size();++i){
      deg[g[u][i]]--;
      if (deg[g[u][i]]==k-1) q.push(g[u][i]);
    }
  }
  if (cnt>0){
    printf("1 %d\n", cnt);
    for (int i=1;i<=n;++i)
      if (deg[i]>=k) printf("%d ", i);
    printf("\n");
    return 1;
  }
  return 0;
}

bool step2(){ // 判断是否存在完全子图
  for (int i=1;i<=n;++i) if (tag[i]) {
    nei[i] = 1;
    for (int j=0;j<v[i].size();++j)
      nei[v[i][j]] = 1;
    bool ok = true;
    for (int j=0;j<v[i].size();++j){
      int u = v[i][j], cnt = 0;
      for (int l=0;l<g[u].size();++l){
        if (nei[g[u][l]]) cnt++;
      }
      if (cnt<k-1) {
        ok = false;
        break;
      }
    }
    nei[i] = 0;
    for (int j=0;j<v[i].size();++j)
      nei[v[i][j]] = 0;
    if (ok) {
      printf("2\n");
      for (int j=0;j<v[i].size();++j)
        printf("%d ", v[i][j]);
      printf("%d\n", i);
      return true;
    }
  }
  return false;
}

int main(){
	scanf("%d",&t);
  while (t--){
    scanf("%d%d%d",&n,&m,&k);
    init();
    int x,y;
    for (int i=1;i<=m;++i){
      scanf("%d%d",&x,&y);
      deg[x]++;deg[y]++;
      g[x].push_back(y);g[y].push_back(x);
    }
    if (1ll*k*(k-1)>2ll*m){
      printf("-1\n");
      continue;
    }
    if (step1()) continue;
    if (step2()) continue;
    printf("-1\n");
  }
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;

const int N = 1e5+2;
const int M = 350;

int n,m,cnt,t,r,k,deg[N];
bool cli[N],nei[N],del[N];
vector<int> g[N],cnd[N],w[N];
queue<int> q;

void init(){
  for (int i=1;i<=n;++i){
    g[i].clear();w[i].clear();
    deg[i] = 0;
    del[i] = 0;
  }
}

bool step1(){
  cnt = n;
  r = 0;
  for (int i=1;i<=n;++i)
    if (deg[i]<k) q.push(i);
  while (!q.empty()){
    int u = q.front(); q.pop();
    cnt--;del[u] = 1;
    if (deg[u]==k-1){
      cnd[++r].clear();
      cnd[r].push_back(u);
      w[u].push_back(r);
      for (int i=0;i<g[u].size();++i) if (!del[g[u][i]]){
        cnd[r].push_back(g[u][i]);
        w[g[u][i]].push_back(r);
      }
    }
    for (int i=0;i<g[u].size();++i){
      deg[g[u][i]]--;
      if (deg[g[u][i]]==k-1) q.push(g[u][i]);
    }
  }
  if (cnt>0){
    printf("1 %d\n", cnt);
    for (int i=1;i<=n;++i)
      if (deg[i]>=k) printf("%d ", i);
    printf("\n");
    return 1;
  }
  return 0;
}

bool step2(){ // 判断是否存在完全子图
  memset(nei,0,sizeof(nei));
  memset(cli,0,sizeof(cli));
  for (int i=1;i<=n;++i) if (w[i].size()){
    nei[i] = 1;
    for (int j=0;j<g[i].size();++j)
      nei[g[i][j]] = 1;
    for (int j=0;j<w[i].size();++j) if (!cli[w[i][j]]){
      int x = w[i][j];
      for (int l=0;l<cnd[x].size();++l)
        if (!nei[cnd[x][l]]){
          cli[x] = 1;
        }
    }
    for (int j=0;j<g[i].size();++j)
      nei[g[i][j]] = 0;
    nei[i] = 0;
  }
  for (int i=1;i<=r;++i)
    if (!cli[i]){
      printf("2\n");
      for (int j=0;j<cnd[i].size();++j)
        printf("%d ", cnd[i][j]);
      printf("\n");
      return true;
    }
  return false;
}

int main(){
	scanf("%d",&t);
  while (t--){
    scanf("%d%d%d",&n,&m,&k);
    init();
    int x,y;
    for (int i=1;i<=m;++i){
      scanf("%d%d",&x,&y);
      deg[x]++;deg[y]++;
      g[x].push_back(y);g[y].push_back(x);
    }
    if (1ll*k*(k-1)>2ll*m){
      printf("-1\n");
      continue;
    }
    if (step1()) continue;
    if (step2()) continue;
    printf("-1\n");
  }
	return 0;
}