#include<cstdio>
#include<algorithm>
#include<stdlib.h>
using namespace std;
struct node{
struct node*left;
struct node*right;
int height;
int data;
};
typedef struct node*AVLTree;
int getheight(AVLTree T)
{
if(T==NULL) return 0;
return T->height;
}
void updateheight(AVLTree A)
{
A->height = max(getheight(A->left),getheight(A->right))+1;
}
AVLTree LL(AVLTree A)
{
AVLTree B = A->left;
A->left = B->right;
B->right = A;
updateheight(A);
updateheight(B);
return B;
}
AVLTree RR(AVLTree A)
{
AVLTree B = A->right;
A->right = B->left;
B->left = A;
updateheight(A);
updateheight(B);
return B;
}
AVLTree LR(AVLTree A)
{
A->left = RR(A->left);
return LL(A);
}
AVLTree RL(AVLTree A)
{
A->right = LL(A->right);
return RR(A);
}
AVLTree insert(AVLTree T,int X)
{
if(!T){
T=(AVLTree)malloc(sizeof(struct node));
T->height = 1;
T->data = X;
T->left=T->right = NULL;
}else if(X < T->data){
T->left = insert(T->left,X);
if(getheight(T->left) - getheight(T->right)==2){
if(X<T->left->data){
T = LL(T);
}else{
T = LR(T);
}
}
}else if(X>T->data){
T->right = insert(T->right,X);
if(getheight(T->left) - getheight(T->right)==-2){
if(X>T->right->data){
T = RR(T);
}else{
T = RL(T);
}
}
}
updateheight(T);
return T;
}
int main()
{
AVLTree A = NULL;
int n,x;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&x);
A = insert(A,x);
}
printf("%d",A->data);
return 0;
}