#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

// Node structure
struct Node {
    int data;
    struct Node *next;
};

// Function to check if string is a valid integer
int isValidNumber(char *s) {
    int i = 0;
    if (s[0] == '-') i++; // allow negative numbers
    for (; s[i] != '\0'; i++) {
        if (!isdigit(s[i])) return 0;
    }
    return 1;
}

// Insert at tail
void insertTail(struct Node **head, int value) {
    struct Node newNode = (struct Node)malloc(sizeof(struct Node));
    newNode->data = value;
    newNode->next = NULL;

    if (*head == NULL) {
        *head = newNode;
    } else {
        struct Node *temp = *head;
        while (temp->next != NULL) {
            temp = temp->next;
        }
        temp->next = newNode;
    }
}

// Remove first occurrence of val
int removeValue(struct Node **head, int val) {
    struct Node *temp = *head, *prev = NULL;

    while (temp != NULL) {
        if (temp->data == val) {
            if (prev == NULL) { // head node to be deleted
                *head = temp->next;
            } else {
                prev->next = temp->next;
            }
            free(temp);
            return 1; // success
        }
        prev = temp;
        temp = temp->next;
    }
    return 0; // not found
}

// 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;
    char input[100];
    int valid = 1;

    for (int i = 0; i < n; i++) {
        scanf("%s", input);
        if (!isValidNumber(input)) {
            valid = 0;
            break;
        }
        insertTail(&head, atoi(input));
    }

    scanf("%s", input);
    if (!isValidNumber(input)) {
        valid = 0;
    }
    int val = atoi(input);

    if (!valid) {
        printf("Invalid input\n");
        return 0;
    }

    if (!removeValue(&head, val)) {
        printf("Value not found.\n");
    } else {
        printList(head);
    }

    return 0;
}