import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (sc.hasNext()) {
String line = sc.nextLine();
String[] input = line.split(" ");
int length = input.length;
int head = Integer.parseInt(input[1]);
int deleteData = Integer.parseInt(input[length - 1]);
Map<Integer, Integer> map = new LinkedHashMap<>();
for (int i = 2; i < length - 2; ) {
map.put(Integer.parseInt(input[i]), Integer.parseInt(input[i + 1]));
i += 2;
}
List<Integer> list = new ArrayList<>();
list.add(head);
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
Integer data = entry.getKey();
if (list.contains(data)) {
continue;
}
Integer lastData = entry.getValue();
list.add(list.indexOf(lastData) + 1, data);
}
list.remove(list.indexOf(deleteData));
for (int i : list) {
System.out.print(i + " ");
}
System.out.println();
}
sc.close();
}
}