#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node*right,*left;
}a;
a*root=NULL;
a*create(int num){
    a*newnode=(a*)malloc(sizeof(a));
    newnode->data=num;
    newnode->right=NULL;
    newnode->left=NULL;
    return newnode;

}
a* ins(a*root,int n){
    if(root==NULL){
     
    if(root->left < n){
        root->left=ins(root->left,n);
    }
    else if(root->right > n){
        root->right=ins(root->right,n);
    }
    return root;
}
void postorder(a*root){
    if(root!=NULL){
    
    postorder(root->left);
    postorder(root->right);
    printf("%d",root->data);
}
    
}
int main(){
    int s,n,i;
    scanf("%d",&s);
    if(s<=0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<s;i++){
        scanf("%d",&n);
        root=ins(root,n);
    }
    postorder(root);
    return 0;
}