#include <iostream>
#include <string>
#include <cctype>
using namespace std;

struct Node {
    int val;
    Node* next;
};

bool isNumeric(const string& s) {
    if (s.empty()) return false;
    int i = 0;
    if (s[0] == '-' && s.size() > 1) i = 1;
    for (; i < s.size(); ++i) {
        if (!isdigit(s[i])) return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    cin.ignore();

    Node* head = nullptr, *tail = nullptr;

    for (int i = 0; i < n; i++) {
        string line;
        getline(cin, line);

        if (!isNumeric(line)) {
            cout << "Invalid input\n";
            // Free memory
            while (head) {
                Node* t = head;
                head = head->next;
                delete t;
            }
            return 0;
        }
        int x = stoi(line);
        Node* node = new Node{x, nullptr};
        if (!head) head = node;
        else tail->next = node;
        tail = node;
    }

    string lastLine;
    getline(cin, lastLine);
    if (!isNumeric(lastLine)) {
        cout << "Invalid input\n";
        while (head) {
            Node* t = head;
            head = head->next;
            delete t;
        }
        return 0;
    }
    int val = stoi(lastLine);

    // Remove first occurrence of val
    Node* temp = head, *prev = nullptr;
    bool found = false;
    while (temp != nullptr) {
        if (temp->val == val) {
            found = true;
            if (prev == nullptr)
                head = temp->next;
            else
                prev->next = temp->next;
            delete temp;
            break;
        }
        prev = temp;
        temp = temp->next;
    }

    if (!found) {
        cout << "Value not found\n";
    } else if (head == nullptr) {
        cout << "List is empty\n";
    } else {
        temp = head;
        while (temp != nullptr) {
            cout << temp->val;
            if (temp->next) cout << " ";
            temp = temp->next;
        }
        cout << "\n";
    }

    // Free memory
    while (head) {
        Node* t = head;
        head = head->next;
        delete t;
    }

    return 0;
}