#include<stdio.h>
#include<stdlib.h>

typedef struct node{
    int data;
    struct node *next;
    struct node *prev;
}Node;

Node*head=NULL,*tail;

void create(int num){
    Node*(newNode)=(Node*)malloc(1*sizeof(newNode));
    
    Node*first=head;
    Node*second=head->next;
    
    newNode->data=num;
    newNode->next=tail;
    head->prev=NULL;
    
    if(head==NULL){
        head=newNode;
        tail=newNode;
    }
    else{
        newNode->tail=NULL;
        newNode->prev=tail;
        tail = newNode;
        
    }
}
void deletion(){

    int val;
    if(head->data == val ){
         head=head->next;
         free(head);
         break;
    }
    else{
        if( second->data == val ){
        head->next=second->next;
        free(second);
        break;
    }
    first=first->next;
    second=second->next;
    
}
void display(){
    Node*itr;
    for(itr=head;itr!=NULL;itr=itr->next){
        printf("%d",itr->data);
    }
}

int main(){
    int size,ind,num;
    int val;
    scanf("%d",&size);
    
    for(ind=0;ind<size;ind++){
        scanf("%d ",&num);
        create(num);
    }
    scanf("%d",&val);
    deletion();
    display();
    return 0;
    
}