// editor3
#include<stdio.h>
#include<stdlib.h>
int greater=0;
typedef struct tree
{
    int data;
    struct tree *left,*right;
}node;

node *create(int n)
{
    node *nd=(node*)malloc(sizeof(node));
    nd->data=n;
    nd->left=nd->right=NULL;
    return nd;
}
node *ins(int n,node *tree)
{
    if(root==NULL)
    {
        return create(n);
    }
    if(n<root->data)
    {
        root->left=ins(n,root->left);
    }
    else
    root->right=ins(n,root->r->right);

    return root;
}
void in(node*root)
{
    if(root==NULL)
    return;
    in(root->left);
    greater=root->data;
    in(root->right);
}
int main()
{
    node *root;
    int n;
    scnaf("%d",&n);
    if(n<0)
    {
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        int data;
        scanf("%d",&data);
        root=ins(data,root);
    }
    in(root);
    printf("%d",greater);
}