#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
struct node{
    int key;
    struct node *left;
    struct node *right;
    int height;
};
int max(int a, int b)
{
    return (a>b)?a:b;
}
int height(struct node *n)
{
    if(n==NULL)
        return 0;
    return n->height;    
}
struct node *newnode(int key)
{
    struct node *node=(struct node*)malloc(sizeof(struct node));
    node->key=key;
    node->left=NULL;
    node->right=NULL;
    node->height=1;
    return (node);
}
struct node *rr(struct node *y)
{
    struct node *x=y->left;
    struct node *t2=x->right;
    x->right=y;
    y->left =t2;
    y->height=max(height(y->left),height(y->right)+1);
    x->height=max(height(x->left),height(x->right)+1);
    return x;
}
struct node *lr(struct node *x)
{
    struct node *y=x->left;
    struct node *t2=y->right;
    
    y->left =x;
    x->right=t2;
    x->height=max(height(x->left),height(x->right)+1);
    y->height=max(height(y->left),height(y->right)+1);
    return x;
}
int getb(struct node *n)
{
    if (n==NULL)
    {
        return 0;
    }
    return height(n->left) - height(n->right);
}
struct node * ccccc(struct node *node,int key)
{
    if(node==NULL)
        return(newnode(key));
    if(key<node->key)
        node->left =insert(node->left,key);
    else if(key > node-> key)
        node->right =insert(node->right,key);
    else
        return node;
        
    node->height=1+max(height(node->left),height(node->right));
    int bal=getb(node);
    if(bal>1 && key <node->left->key)
        return rr(node);
    if(bal<-1 && key>node->lright->key)
        return lr(node);
    if(bal >1 && key> node->right->key){
        node->left=ll(node->left);
        return rr(node);}
    if(bal<-1 && key<node->right->k){
        node->right=rr(node->right);
        return lr(node);
    }
    return node:
}
void ino(struct node*root)
{
    if(root!=NULL)
    {
        ino(root->left);
        printf("%d",root->key);
        ino(root->right);
    }
}
int main()
{
    struct node*r=NULL;
    int a=scanf("%d",&a);
    int del=scanf("%d",&del);
    for(int i=0;i<n;i++)
    {
        int val=scanf("%d",&val);
        r=insert(r,val);       
    }
    ino(r);
    return 0;
    
}