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