#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *left;
    struct node *right;
}Node;
Node* root=NULL;
Node* create(int v){
    Node *newnode=(Node*)malloc(sizeof(Node));
    newnode->data=v;
    newnode->left=newnode->right=NULL;
    return newnode;
}
Node *insert(Node* root,int v){
    if(root==NULL)
        return create(v);
    if(v< root->data)
        root->left=insert(root->left,v);
    else
        root->right=insert(root->right,v);
    return root;
}
void order(Node* root){
    if(root==NULL)
        return;
    order(root->left);
    order(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;
    }
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        if(x==-1)
            return N;
        root=insert(root,x);
    }
    order(root);
    return 0;
}