#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
    int data;
    struct Node*next;
}Node;
Node*newNode(int val){
    Node*n=malloc(sizeof(Node));
    n->data=val;
    n->next=NULL;
    return n;
}
int main(){
    int n,x;
    scanf("%d",&n);
    if(n<=0)return printf("Node not found"),0;
    
    Node*head=NULL,*tail=NULL;
    for(inti=0;val;i<n;i++) {
        scanf("%d",&val);
        Node*t=newNode(val);
        if(!head)head=tail=t,t->next=head;
        else tail->next=t,tail=t,tail->next=head;
    }
    scanf("%d ",&x);
    Node*cur=head,*pre=tail;
    do{
        if(cur->head==x){
            if(cur==head)head=(head==head->next)?NULL:head->next,tail->next=head;
            else pre->next=cur->next,(cur==tail)&&(tail=pre);
            free(cur);
            if(!head)return printf("Node not found"),0;
            for(cur=head;cur;cur=cur->next){
                printf("%d",cur->data);
                if(cur->next==head)break;
            }
            return 0;
        }
        pre=cur;cur=cur->next;
    }while(cur!=head);
    printf("Node not found");
}