import java.util.Objects; import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int size = sc.nextInt();
int startNode = sc.nextInt();
ListNode pre = new ListNode(startNode);
ListNode.size = 1;
size--;
while (size > 0) {
int nodeValue = sc.nextInt();
int preValue = sc.nextInt();
ListNode cur = pre;
int curSize = ListNode.size;
for (int i = 0; i < curSize; i++) {
if (cur.value == preValue) {
ListNode temp = cur.next;
cur.next = new ListNode(nodeValue);
ListNode.size++;
cur.next.next = temp;
}
cur = cur.next;
}
size--;
}
int removeValue = sc.nextInt();
ListNode cur = pre;
if (removeValue == cur.value) {
pre = cur.next;
} else {
while (!Objects.isNull(cur.next)) {
if (removeValue == cur.next.value) {
cur.next = cur.next.next;
}
cur = cur.next;
}
}
cur = pre;
while (!Objects.isNull(cur)) {
System.out.print(cur.value + " ");
cur = cur.next;
}
}
}
private static class ListNode {
static int size;
int value;
ListNode next;
public ListNode(int value) {
this.value = value;
}
}
}