#include <stdio.h>
#include <stdlib.h>

typedef struct node{
    int data;
    struct node *prev;
    struct node *next;
}Node;

int cnt=0;
Node *head = NULL,*tail;

void create(int num){
    Node *newnode = (Node*) malloc (1 * sizeof(Node));
    newnode->data = num;
    newnode->prev = newnode->next = NULL;
    if(head == NULL){
        head = newnode;
        tail = newnode;
    }
    else{
        newnode->prev = tail;
        tail->next = newnode;
        tail = newnode;
    }
    // head->prev = tail;
    // tail->next = head;
}
int deleted(int x,int cnt){
    Node *first,*second,*itr;
    first = head;
    second = head->next;
    for(itr=head->next;itr!=NULL;itr=itr->next){
        if(itr->data == x){
            cnt=1;
            first->next = second->next;
            
            // free(second);
        }
        first = first->next;
        second = second->next;
    }
    return cnt;
}

void display(){
    Node *itr;
    for(itr=head;itr!=NULL;itr=itr->next){
        
        printf("%d ",itr->data);
    }
}

int main(){
    int size,num,ind,x,cnt;
    scanf("%d",&size);
    for(ind=0;ind<size;ind++){
        scanf("%[^\n]d",&num);
        create(num);
    }
    scanf("%d",&x);
    
    if(deleted(x,cnt) == 0){
        printf("Node not found");
        return 0;
    }
    display();
    return 0;
}