import java.util.Scanner;

class Node {
    int data;
    Node next;

    Node(int data) {
        this.data = data;
        this.next = null;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        try {
            int n = sc.nextInt();

            if (n < 0 || n > 1000) {
                System.out.println("Invalid input");
                return;
            }

            Node head = null, tail = null;

            // Build linked list
            for (int i = 0; i < n; i++) {
                if (!sc.hasNextInt()) {
                    System.out.println("Invalid input");
                    return;
                }
                int val = sc.nextInt();
                Node newNode = new Node(val);
                if (head == null) {
                    head = newNode;
                    tail = newNode;
                } else {
                    tail.next = newNode;
                    tail = newNode;
                }
            }

            // Read the value to be removed
            if (!sc.hasNextInt()) {
                System.out.println("Invalid input");
                return;
            }
            int target = sc.nextInt();

            // Traverse & remove first occurrence
            Node temp = head, prev = null;
            boolean found = false;

            while (temp != null) {
                if (temp.data == target) {
                    found = true;
                    if (prev == null) {
                        head = temp.next; // remove head
                    } else {
                        prev.next = temp.next;
                    }
                    break;
                }
                prev = temp;
                temp = temp.next;
            }

            // Handle outputs
            if (!found) {
                System.out.println("Value not found");
            } else if (head == null) {
                System.out.println("List is empty");
            } else {
                // Print updated list
                temp = head;
                while (temp != null) {
                    System.out.print(temp.data);
                    if (temp.next != null) System.out.print(" ");
                    temp = temp.next;
                }
            }

        } catch (Exception e) {
            System.out.println("Invalid input");
        }
    }
}