import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] strs = scan.nextLine().split(" ");
        int n = Integer.valueOf(strs[0].trim());
        int head = Integer.valueOf(strs[1].trim());
        int delete = Integer.valueOf(strs[strs.length - 1].trim());
        ArrayList<Integer> arr = new ArrayList<>(6);
        arr.add(head);
        for (int i = 2; i < strs.length - 1; i += 2) {
            int l = Integer.valueOf(strs[i].trim());
            int r = Integer.valueOf(strs[i + 1].trim());
            int index = arr.indexOf(Integer.valueOf(r));
            arr.add(index + 1, l);
        }
        arr.remove(Integer.valueOf(delete));
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }
}