#include <stdio.h>
#include <stdlib.h>
struct Node {
    int data;
    struct Node* next;
};
int main() {
    int n, x;
    scanf("%d", &n);
    
    if (n <= 0) {
        printf("Invalid Input");
        return 0;
    }
    struct Node *head = NULL, *temp, *prev;
    for (int i = 0; i < n; i++) {
        temp = (struct Node*)malloc(sizeof(struct Node));
        scanf("%d", &temp->data);
        temp->next = head;
        head = temp;
    scanf("%d", &x);
    temp = head;
    prev = NULL;
    while (temp != NULL) {
        if (temp->data == x) {
            if (prev == NULL) {
                head = temp->next; 
            } else {
                prev->next = temp->next;
            }
            free(temp);
            break;
        }
        prev = temp;
        temp = temp->next;
    }

    if (temp == NULL) {
        printf("Node not found");
    } else {
        temp = head;
        while (temp != NULL) {
            printf("%d ", temp->data);
            temp = temp->next;
        }
    }
    return 0;