// editor3
#include<stdio.h>
typedef struct node{
    int dat;
    struct node *left,*right;
}Node;

Node *root =NULL;

Node* create(int num)
{
    new *newNode =(Node*)malloc(sizeof(Node)) ;
    newNode->data=num;
    newNode->left=NULL;
    newNode->right=NULL;
    return newNode;
}

node* insert(Node *root,int num)
{
    if(root==NULL)
        return create(num);
    if(num<root->data)
        root->left=inser(root->left,num);
    else if(num>root->data)
        root->right=inser(root->right,num);
        return root;
}
void max(node *root )
{
    if(root!=NULL)
    {
        if(root->right!=NULL)
        return max(root->right);
        else
          printf("%d",root->data);
    }
}
int main()
{
    int size,num;
    scanf("%d",&size);
    for(int i=0;i<size;i++)
    {
        scanf("%d",&num);
        root=insert(root,num);
    }
    max(root);
    return 0;
}