#include<stdio.h>
#include<stdlib.h>
struct node{
    int d;
    struct node *r,*l;
};
struct node*cr(int val)
{
    struct node *n=(struct node*)malloc(sizeof(struct node));
    n->d=val;
    n->l=n->r=NULL;
    return n;
}
struct node*in (struct node *r,int val)
{
    if(r==NULL)
    return cr(val);
    if(val<r->d)
    r->l=in(r->l,val);
    else if(val>r->d)
    r->r=in(r->r,val);
    return r;
}
struct node *min(struct node*r)
{
    while(r->l!=NULL)
    r=r->l;
    return r;
}
struct node * del(struct node * r,int k)
{
    if(r==NULL)
    return NULL;
    if(k<r->d)
    r->l=del(r->l,k);
    else if(k>r->d)
    r->r=del(r->r,k);
    else
    {
        if(r->l==NULL)
        {
            struct node *temp=r->r;
            free(r);
            return temp;
        }
        else if(r->r==NULL)
        {
            struct node*temp=r->l;
            free(r);
            return temp;
        }
        struct node *temp=min(r->r);
        r->d=temp->d;
        r->r=del(r->r,temp->d);
        
    }
    return r;
}
void pre(struct node*r)
{
    if(r!=NULL)
    {
        printf("%d ",r->d);
        pre(r->l);
        pre(r->r);
        
    }
}
int valid(int n)
{
    return (n>=0 && n<=20);}
int main()
{
    int x,n;
    
    if(scanf("%d%d",&n,&x)!=2||!valid(n))
    {
        printf("Invalid input\n");
        return 0;
    }
    struct node * r=NULL;
    int val;
    for(int i=0;i<n;i++){
        if(scanf("%d",&val)!=1||val<0||val>1000)
        {
        printf("Invalid input");
        return 0;}
        r=in(r,val);
    }
    r=del(r,x);
    pre(r);
    printf("\n");}
    return 0;
}