#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node*prev;
struct node*next;
};
int main(){
    int n,x;
    scanf("%d",&n);
    struct node*head=NULL;
    struct node*tail=NULL;
    for(int i=0;i<n;i++){
        int val;
        scanf("%d",&val);
        struct node*newnode=(struct node*)malloc(sizeof(struct node));
        newnode->data=val;
        newnode->prev=tail;
        newnode->next=NULL;
        if(head==NULL)
            head =newnode;
         else
          tail->next=newnode;
          tail=newnode;
    }
    scanf("%d",&x);
    struct node*temp=head;
    int found=0;
    while(temp!=NULL);
    if(temp->data==x){
        found=-1;
        if(temp->prev!=NULL)
        temp->prev->next=temp->next;
        else
        head=temp->next;
        if(temp->next!=NULL)
        temp->next->prev=temp->prev;
        free(temp);
        break;
        
    }
    temp=temp->next;
}
if(!found){
    printf("Node not found");
    return 0;
}
temp=head;
while(temp!=NULL){
    printf("%d",temp->data);
    if(temp->next!=NULL)
    printf("");
    temp=temp->next;
  }
  return 0;
}