#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node*left,*right;
}a;
a*root=NULL;
a*create(int num){
    a*newNode=(a*)malloc(sizeof(a));
    newNode->data=num;
    newNode->left=NULL;
    newNode->right=NULL;
    return newNode;
}
a*insert(a*root,int num){
    if(root==NULL){
        return create(num);
    }
    if(num<root->data){
        root->left=insert(root->left,num);
    }
    else if(num>root->data){
        root->right=insert(root->right,num);
    }
    return root;
}
a*postorder(a*root){
    if(root->left!=NULL && root->right!=NULL){
        postorder(root,num);
        
    }
    else{
        return root;
    }

}
int main(){
    int size,num;
    scanf("%d",&size);
    if(size<=0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<size;i++){
        scanf("%d",&num);
        root=insert(root,num);
    }
    a*ans=postorder(root);
    printf("%d ",ans->data);
    return 0;
}