#include <stdio.h>
#include <stdlib.h>
typedef struct Node{
    int data;
    struct Node* next;
    struct Node* prev;
}Node;

Node *head=NULL, *tail, *temp, *temp2;

void create(int num){
    Node *new = (Node*)malloc(1*sizeof(Node));
    new->data=num;
    new->prev=NULL;
    new->next=NULL;
    
    if(head==NULL){
        head=new;
        tail=new;
    }
    else{
        new->prev=tail;
        tail->next=new;
        tail = new;
    }
}

void deletion(int val){
    if(head->data == val){
        head = head->next;
        head->prev = NULL;
    }
    else if(tail->data == val){
        tail->prev->next=NULL;
    }
    else{
        temp = head;
        while(temp->data==val){
            temp = temp->next;
        }
        temp2 = temp->next->next;
        temp->next=temp2;
    }
}

void display(){
    Node *i;
    for(i=head;i!=NULL;i=i->next){
        pritnf("%d",i->data);
    }
}

int main(){
    int n,i,num,val;
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    
    for(i=0;i<n;i++){
        scanf("%d",&num);
        create(num);
    }
    scanf("%d",&val);
    deletion(val);
    display();
    return 0;
}