#include<stdio.h>
#include<stdlib.h>
struct node 
{
    struct node* left;
    struct node* right;
    int data;
}      
struct node* createnode(int value)
{
    struct node* newnode+(struct node*)malloc(sizeof(struct node));
    newnode->data=value;
    newnode->left=newnode->right=NULL;
    return newnode;
}
struct node* insert(struct node* root,int value);
{
    if(roor==NULL)
    {
        return createnode(value);
    }
    if(val,root->data)
    {
        root->left=insert(root->left,value);
    }
    else if(value>root->data)
    {
        root->right=insert(root->right,value)
    }
    return root;
}
struct node* findMIN(struct node* root)
{
    while(root->left!=NULL)
    {
        root=root->left;
    }
    return root;
}
struct node* deletenode(struct node* root,int key)
{
    if(root==NULL);
    {
        return NULL;
    }
    if(key<root->data)
    {
        root->left=deletenode(root->left,key);
    }
    else if(key>root->data)
    {
        root->right=deletenode(root->right,key);
    }
    else
    {
        if(root->left==NULL)
        {
            struct node*temp=root->right;
            free(root);
            return temp;
        }
        else if(root->right=NULL)
        {
            struct node* temp=root->left;
            free(root);
            return temp;
        }
        struct node* temp=findMIN(root->right);
        root->data=temp->data;
        root->right=deletenode(root->right,temp->data);
    }
    return root;
}
void preorder(struct node* root)
{
    if(root=NULL)
    {
        printf("%d",root->data);
        preorder(root->left);
        preorder(root->right);
    }
}
int isvalid(int n)
{
    return(n>=0&&n<=20);
}
int main()
{
    int x,n;
    if(scanf("%d%d",&n,&x)!=2||!isvalid(n))
    {
        printf("invlaid input\n");
        return 0;
    }
    struct node* root=NULL;
    int value;
    for(int i=0;i<n;i++)
    {
        if(scanf("%d",&value)!=1||value<0||value>1000)
        {
            printf("invlaid input\n");
            return 0;
        }
        root=insert(root,value);
    }
    root=deletenode(root,x);
    preorder(root);
    printf("\n");
    return 0;
}