#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct *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*ins(a*root,int num){
    if(root==NULL){
        return create(num);
    }
    if(num<root->data){
        root->left=ins(root->left,num);
    }
    if(num>root->data){
        root->right=ins(root->right,num);
    }
    return root;
}
void postorder(node *root){
    if(root!=NULL){
    postorder(root->left);
    postorder(root->right);
    if(root->left==NULL && root->right==NULL){
        printf("%d",root->data);
    }
    }
}
int main(){
    int s,n,i;
    scanf("%d",&s);
    if(s<=0){
        printf("Invalid input");
        return 0;
    }
    for(i=0;i<s;i++){
        scanf("%d",&n);
        root=ins(root,n);
        
    }
    postorder(root);
    return 0;
}