#include<stdio.h>
#include<stdlib.h>

struct node
{
    int key;
    struct node *left,*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 *rightRotate(struct node *y)
{
    struct node *x=y->left;
    struct node *T2=x->right;
    
    x->right=y;
    y->right=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 *leftRotate(struct node *x)
{
    struct node *y=x->left;
    struct node *T2=y->right;
    
    y->right=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 y;
}
int getBalance(struct node *N)
{
    if(N=NULL)
      return 0;
    return height(N->left)-height(N->right);
}
struct node *insert(struct node *root,int key)
{
    if(root==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 balance=getBalance(node);
    if(balance>1&&key>node->left->key)
    {
        node->right=rightRotate(node->right);
        return leftRotate(node);
    }
    return node;
}
struct node *deleteNode(struct node *root,int key)
{
    if(root==NULL)
       return root;
    
    if(key<root->key)
       root->left=deleteNode(root->left,key);
    else if(key>root->key)
       root->right=deleteNode(root->right,key);
    else
    {
        if((root->left==NULL)||(root->right==NULL))
        {
            struct node *temp=root->left?root->left:root->right;
            
            if(temp==NULL)
            {
                temp=root;
                root=NULL;
            }
            else
            {
                *root=*temp;
            }
             free(temp);
        }
        else
        {
            struct node*temp=minvalueNode(root->right);
            root->key=temp->key;
            root->right=deleteNode(root->right,temp->key);
            
            
        }

    }
    if(root==NULL)
      return root;
    root->height=1+max(height(root->left),height(root->right));
    int balance=get balance(root);
    if(balance>1&&getbalance(root->left)>=0)
        return rightRotate(root);
    if(balance>1&&getbalance(root->left)<0)
    {
        root->left=leftRotate(root->left);
            return rightRotate(root);
    }
    if(balance<-1&&getbalance(root->right)<=0)
        return leftRotate(root);
    if(balance<-1&&getbalance(root->right)>0)
    {
        root->right=rightRotate(root->left);
            return leftRotate(root);
    }
    return root;
    
} 
void preOrder(struct node*root)
{
    if(root!=NULL)
    {
        printf("%d",root->key);
        preOrder(root->left);
        preOder(root->right);
    }
}
int main()
{
    int n,x;
    if(scanf("%d%d",&n,&x)!=2||n<=0)
    {
        printf("Invalid input\n");
        return 0;
    }
    struct node*root=NULL;
    for(int i=0;i<n;i++)
    {
        int val;
        if(scanf("%d",&val)!=1||val<0)
        {
            printf("Invalid input\n");
            return 0;
        }
        root=insert(root,val);
    }
    root=deleteNOde(root,x);
    preOrder(root);
    printf("\n");
    return 0;
    
}