#include<stdio.h>
#include<stdlib.h>

typedef struct Tree{
    int data;
    struct Tree *left,*right;
}tree;

tree *root=NULL;
tree *bran;

tree* create(int num)
{
    bran=(tree*)malloc(1 * sizeof(tree));
    bran->data=num;
    bran->left=NULL;
    bran->right=NULL;
    return bran;
}

tree* insert(tree* root,int num){
    if(root==NULL){
        return create(num);
    }
    if(root->data>num){
        root->left=insert(root->left,num);
        
    }
   else if(root->right<num){
        root->right=insert(root->right,num);
    }
    return root;
}

void postorder(tree *root){
    if(root!=NULL){
        postorder(root->left);
        postorder(root->right);
        printf("%d"root->data);
    }
}

int main(){
    int size;
    int num,ind;
    scanf("%d",&size);
    if(size<0){
        printf("Invalid input");
        return 0;
    }
    for(ind=0;ind<size;ind++){
        scanf("%d",&num);
        root=insert(root,num);
    }
    postorder(root);
    return 0;
}