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