// editor3
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *left,*right;
}nd;
nd *root=NULL;
nd *create(int num){
    nd *newnode=(nd*)malloc(sizeof(nd));
    newnode->data=num;
    newnode->left=NULL;
    newnode->right=NULL;
    return newnode;
}
nd *insertBST(nd *root,int num){
    if(root==NULL){
        return create(num);
    }
    if(num<root->data)
        root->left=insertBST(root->left,num);
    else if(num>root->data)
        root->right=insertBST(root->right,num);
        return root;
}

void level(nd *root){
     if(root==NULL)
        return;
    nd *queue[100],
    int front=0,rear=0;
    queue[rear++]=root;
    while(front<rear){
        nd *curr=queue[front++];
        printf("%d",curr->data);
        if(curr->left){
            queue[rear++]=curr->left;
        }
        if(curr->right){
            queue[rear++]=curr->right;
        }
    }
}
int main(){
    int n,num;
    nd *root=NULL;
    scanf("%d",&n);
        if(n<0){
            printf("Invalid input");
            return 0;
        }for(int i=0;i<n;i++){
        scanf("%d",&num);
       root=insertBST(root,num);
    }
    level(root);
    return 0;
}