// editor5
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node*left;
    struct node*right;
    
}node;
node* newnode(int value){
node* node=(node*)malloc(sizeof(node));
node->data=value;
node->left=node->right=NULL;
return node;
}
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;
}