#include <stdio.h>
#include <stdlib.h>
typedef struct node{
    int data;
    struct node *prev;
    struct node *next;
}nd;
nd *head=NULL,*tail,*temp=NULL,*newnode=NULL;
int found;
void create(int val){
    newnode=(nd*)malloc(sizeof(nd));
    newnode->data=val;
    newnode->prev=NULL;
    newnode->next=NULL;
    if(head==NULL){
        head=newnode;
        tail=newnode;
    }else{
        tail->next=newnode;
        newnode->prev=tail;
        tail=newnode;
    }
}
void display(){
    temp=head;
    while(temp!=NULL){
        printf("%d ",temp->data);
        temp=temp->next;
    }
}
void delval(int val){
    temp=head;
    if(head->data==val){
        found=1;
        printf("%d",found);
        head=head->next;
        head->prev=NULL;
    }else if(tail->data==val){
        tail->prev->next=NULL;
        tail=tail->prev;
    }else{
        while(temp->data!=val){
            temp=temp->next;
        }
        if(temp->data==val){
            temp->prev->next=temp->next;
            temp->next->prev=temp->prev;
        }
        
    }
}
int main(){
    int n;
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<n;i++){
        int x;
        if(scanf("%d",&x)!=1||x>1000||x<-1000){
            printf("Invalid input");
            return 0;
        }
        create(x);
    }
    int y;
    scanf("%d",&y);
    delval(y);
    /*if(found!=0){
        printf("Node not found");
        return 0;
    }
    //display();
    return 0;
}