#include<stdio.h>
#include<stdlib.h>
struct Node{
    int key;
    struct Node*left;
    struct Node*right;
};
struct Node*createNode(int value){
     struct node*newNode=(struct Node*)malloc(sizeof(struct node));
     newNode->data=value;
     newNode->left=NULL;
     newNode->right=NULL;
     return newNode;
}
 struct Node*insert(struct Node*root,int value){
     if(root==NULL)
     return createNode(value);
     if(value<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->root;
             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 n,x;
          if(scanf("%d%d",&n,&x)!=2||! isvalid(n)){
              printf("Invalid input\n");
              return 0;
          }
          struct Node*root=NULL;
          int value;
          for(int i=0;i<n;i++){
              if(scanf("%d",&value)!=1||value<o||value>1000){
                  printf("Invalid input\n");
                  return 0;
              }
                root=insert(root,value);
              
          }
          root=DeleteNode(root,x);
          preOrder(root);
          printf("\n");
          return 0;
 }