#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;
    return newNode;
}

Node *insert(Node *root,Node *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)
        return root->data;
}

int main(){
    int n;
    int value;
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    
    Node *root=NULL;
    for(int itr=0;itr<n;itr++){
        
        scanf("%d",&value);
        root=insert(root,value);
    }
    
    int maxVal = findMax(root);
    printf("%d",maxVal);
    
    return 0;
}