#include<stdio.h>
#include<stdlib.h>
struct T{
    int v;
    struct T*l;
    struct T*r;
};
int main(){
    int n,v;
    struct T *root=NULL,*newNode,*c,*p;
    if(scanf("%d",&n)!=1){
        printf("Invalid input\n");
        return 1;
    }
    for(int i=0;i<n;++i){
        if(scanf("%d",&v)!=1){
            printf("Ivalid input");
            return 1;
        }
        newNode=(struct T*)malloc(sizeof(struct T));
        newNode->v=v;
        newNode->l=newNode->r=NULL;
        if(root == NULL){
            root = newNode;
        }
        else{
            c = root;
            p = NULL;
            while(c!= NULL){
                p=c;
                if(v<c->v){
                    c=c->r;
                }
            }
            if(v<p->v){
                p->l = newNode;
            }else{
                p->r =newNode;
            }
        }
    }
    if(root != NULL){
        c=root;
        while(c->l != NULL){
            c=c->l;
        }
        printf("%d\n",c->v);
    }
    return 0;
}