// editor5
#include<stdio.h>
#include<stdlib.h>
 struct node{
    int data;
    struct node*left;
    struct node*right;
    
};
/*node* newnode(int value){
node* newnode=(node*)malloc(1*sizeof(node));
      node ->data=value;
       node ->left=node->right=NULL;
return node;
}*/
struct node* newnode(int value){
    struct node* temp=(struct node*)malloc(sizeof(struct node));
    temp->data=value;
    temp->left=temp->right=NULL;
    return temp;
}
node*insert(node* root,int value){
    if(root==NULL)
    return newnode(value);
    if(value<root->data)
    root->left=insert(root->left,value);
    else
    root->right=insert(root->right,value);
    }
void printleafnodes(node*root){
    if(root==NULL)
    return;
    printleafnodes(root->left);
    printleafnodes(root->right);
    if(root->left==NULL && root->right==NULL)
    printf("%d ",root->data);
}
int main(){
    int n;
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    node*root=NULL;
    for(int i=0;i<n;i++){
        int val;
        scanf("%d",&val);
        root=insert(root,val);
    }
    printleafnodes(root);
    return 0;
}