#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *left;
    struct node *right;
}Node;
Node *root=NULL;
Node *create(int val){
    Node *newnode=(Node*)malloc(sizeof(Node));
    newnode->data=val;
    newnode->left=NULL;
    newnode->right=NULL;
    return newnode;
}
Node *insert(Node *root,int val){
    if(root==NULL){
        return create(val);
    }
    Node *queue[200];
    int front=0,rear=0;
    queue[rear++]=root;
    while(front<rear){
        Node *temp=queue[front++];
        if(temp->left==NULL){
            temp->left=create(val);
            return root;
        }
        else{
            queue[rear++]=temp->left;
        }
        if(temp->right==NULL){
            temp->right=create(val);
            return root;
        }
        else{
            queue[rear++]=temp->right;
        }
    }
}
void preorder(Node *root){
    if(root==NULL)
        return;
    if(root->left==NULL && root->right==NULL)
        printf("%d ",root->data);
    preorder(root->left);
    preorder(root->right);
    
}
int main(){
    int n;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    int x;
    for(int i=0;i<n;i++){
        scanf("%d",x);
        if(arr[i]==-1)
            continue;
        root=insert(root,x);
    }
    preorder(root);
    return 0;
}