#include<stdio.h>
#include<stdlib.h>

typedef struct node{
    int data;
    struct Node *left;
    struct Node *right;
}Node;

Node *createNode(int value){
    Node *newNode = (Node*) malloc (sizeof(Node));
    newNode->data=value;
    newNode->left =newNode->right = NULL;
    return newNode;
}

Node *Insert(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(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;
    }
    
    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;
}