#include<stdio.h>
#include<stdlib.h>
typedef struct list
{
    int data;
    struct list *next;
}node;
node*head=NULL,*tail=NULL;
void create(int n)
{
    node *newnode=(node*)malloc(sizeof(node));
    newnode->data=n;
    newnode->next=NULL;
    if(head==NULL)
    {
        head=newnode;
        tail=newnode;
    }
    else
    {
        tail->next=newnode;
        tail=newnode;
    }
}
void print(){
    node *temp=head;
    while(temp!=NULL)
    {
        printf("%d ",temp->data);
        temp=temp->next;
    }
}
void del(int e)
{
    if(head==NULL)
    {
        printf("Node not found");
    }
    else
    {
        node *temp=head,*temp2=NULL,*ptr=NULL;
        while(temp!=NULL)
        {
            if(temp->data==e)
            {
                if(head->data==temp->data)
                {
                    ptr=temp;
                    head=head->next;
                    free(temp);
                    print();
                    break;
                }
                temp2=temp;
                temp=temp->next;
            }
            if(ptr==NULL)
            {
                print("Invalid Input");
            }
        }
    }

}
int main()
{
    int n,data,dl;
    scanf("%d",&n);
    if(n<0)
    {
       print("Invalid Input");
       return 0;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&data);
        create(data);
    }
    scanf("%d",&dl);
    del(dl);
}