#include<stdio.h>
#include<stdlib.h>

struct node{
    int data;
    struct Node *left;
    struct Node *right;
};

struct node *createNode(int value){
    struct node *newNode = (struct Node*) malloc (sizeof(struct node));
    newNode->data=value;
    newNode->left = NULL;
    newNode->right = NULL;
    return newNode;
}

struct node *Insert(struct node *root,int value){
    if(root == NULL)
        return createNode(value);
    if(value < root->data)
        root->left = Insert(root->left,value);
    else
        root->right = Insert(root->right,value);
    return root;
}

int findMax(struct node *root){
    if(root == NULL)
        return -1;
    while(root->right != NULL)
        root = root->right;
    return root->data;
}

int main(){
    int n;
    
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    
    struct node *root=NULL;
    for(int itr=0;itr<n;itr++){
        int value;
        scanf("%d",&value);
        root=Insert(root,value);
    }
    
    int maxVal = findMax(root);
    printf("%d",maxVal);
    
    return 0;
}