#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
struct node{
    int key;
    struct node*left;
    struct node*right;
    int height;
};
int height(struct node*n)
{
    if(n==NULL)
    return 0;
    return n->height;
}
int max(int a,int b){
    return(a>b)?a:b;
}
struct node*newnode(int key)
{
    struct node*nod=(struct node*)malloc(sizeof(struct node));
    nod->key=key;
    nod->left=nod->right=NULL;
    nod->height=1;
    return nod;
}
struct node*rightRotate(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*leftRotate(struct node*x)
{
    struct node*y=x->right;
    struct node*t2=y->left;
    y->left=x;
    x->right=t2;
     y->height=max(height(y->left),height(y->right))+1;
    x->height=max(height(x->left),height(x->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 *nod,int key)
{
    if(nod==NULL)
    return newnode(key);
    if(key<nod->key)
        nod->left=insert(nod->left,key);
        else if(key>nod->key)
        nod->right=insert(nod->right,key);
        else
        return nod;
        nod->height=1+max(height(nod->left),height(nod->right));
        int balance=getBalance(node);
        if(balance>1&&key<nod->left->key)
        return rightRotate(nod);
        if(balance<-1&&key>nod->right->key)
        return leftRotate(node);
        if(balance>1&&key>nod->left->key)
        {
            nod->key=leftRotate(nod->left);
            return rightRotate(node);
        }
        if(balance<-1&&key<nod->right->key){
            nod->right=rightRotate(node->right);
            return leftRotate(nod);
        }
    }if(balance<-1&&key<nod->right->key)
    {
        nod->right=rightRotate(node->right);
        return leftRotate(node);
    }
    return node;
}
struct node *minvalue(struct node*nod)
{
    struct node*current=nod;
    while(current->left!=NULL)
    current=current->left;
    return current;
}
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=getbalance(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)
        {
            root->right=rightRotate(root->right);
            return leftRotate(root);
        }
        return root;
    }
    void preOrder(struct node*root){
        if(root!=NULL){
            printf("%d",root->key);
            preOrder(root->left);
            preOrder(root->right);
        }
    }
    int main()
    int n,x;
    if(scanf("%d %d",&n,&x)!=2||n<0)
    {
        printf("Invalid Input");
        return 0;
    }
    struct node*root=NULL;
    for(int i=0;i<n;i++)
    {
        int id;
        if(scanf("%d",&id)!=1){
            printf("Invalid Input");
            return 0;
        }
        root=insert(root,id);
    }
    root=deleteNode(root,x);
    if(root==NULL){
        printf()
    }
}