#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

struct Node {
    int data;
    struct Node* next;
};

struct Node* head = NULL;

// Function to validate numeric input
int isValid(char str[]) {
    for (int i = 0; str[i]; i++) {
        if (!isdigit(str[i])) return 0;
    }
    return 1;
}

// Function to insert node at the end
void insertEnd(int value) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = value;
    newNode->next = NULL;

    if (head == NULL) {
        head = newNode;
        return;
    }

    struct Node* temp = head;
    while (temp->next != NULL) {
        temp = temp->next;
    }
    temp->next = newNode;
}

// Function to delete first occurrence of val
int deleteValue(int val) {
    struct Node* temp = head;
    struct Node* prev = NULL;

    while (temp != NULL) {
        if (temp->data == val) {
            if (prev == NULL) {
                head = temp->next;
            } else {
                prev->next = temp->next;
            }
            free(temp);
            return 1; // Deleted
        }
        prev = temp;
        temp = temp->next;
    }
    return 0; // Not found
}
// Function to display the list
void display() {
    if (head == NULL) {
        printf("List is empty\n");
        return;
    }
    struct Node* temp = head;
    while (temp != NULL) {
        printf("%d ", temp->data);
        temp = temp->next;
    }
}

int main() {
    char input[100];
    scanf("%s", input);
    if (!isValid(input)) {
        printf("Invalid input\n");
        return 0;
    }

    int n = atoi(input);
    for (int i = 0; i < n; i++) {
        scanf("%s", input);
        if (!isValid(input)) {
            printf("Invalid input\n");
            return 0;
        }
        insertEnd(atoi(input));
    }

    scanf("%s", input);
    if (!isValid(input)) {
        printf("Invalid input\n");
        return 0;
    }

    int val = atoi(input);
    if (!deleteValue(val)) {
        printf("Value not found\n");
        return 0;
    }

    display();
    return 0;
}