Problem: During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.

Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of the student that stands in line directly in front of him, and the student that stands in line directly behind him. If no one stands before or after a student (that is, he is the first one or the last one), then he writes down number 0 instead (in Berland State University student IDs are numerated from 1).

After that, all the students went about their business. When they returned, they found out that restoring the queue is not such an easy task.

Help the students to restore the state of the queue by the numbers of the student ID's of their neighbors in the queue.

Input

The first line contains integer n (2 ≤ n ≤ 2·105) — the number of students in the queue. 

Then n lines follow, i-th line contains the pair of integers ai, bi (0 ≤ ai, bi ≤ 106), where ai is the ID number of a person in front of a student and bi is the ID number of a person behind a student. The lines are given in the arbitrary order. Value 0 is given instead of a neighbor's ID number if the neighbor doesn't exist.

The ID numbers of all students are distinct. It is guaranteed that the records correspond too the queue where all the students stand in some order.

Output

Print a sequence of n integers x1, x2, ..., xn — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one.

Examples

Input

4
92 31
0 7
31 0
7 141


Output

92 7 31 141 

Note

The picture illustrates the queue for the first sample.

<image>

Solution (in JAVA):

Solution:
import java.io.*;
import java.math.*;
import java.util.*;
import java.awt.*;

public class Main {
    static Scanner input = new Scanner(System.in);
    static final double EPS = 1e-8;
    static final int OO = (int) 1e9;
    static int n; 
    static int m; 
    static boolean[][] vis;
    static ArrayList<ArrayList<Integer>> graph;
    static int[] colors;
    static ArrayList<Integer> lengths;
    static int[] d4x = {-1, 1, 0, 0};
    static int[] d4y = {0, 0, -1, 1};
    static int[] d8j = {-1, 1, 0, 0, 1, 1, -1, -1};
    static int[] d8i = {0, 0, -1, 1, 1, -1, 1, -1};
    static char grid[][];
    static ArrayList<Integer> topo;

    static HashMap<String, Integer> h;
    static int[] length;
    static Stack<Integer> s = new Stack<>();
    static int count;
    static int[] arr;
    static int[] d;
    static char ch; 
    static ArrayList<Integer> anas;
    static int sz;
    static boolean isPrime[];
    static char[] charArr;
    static int val;
    static String[][] str;
    enum color{white, black};
    static int types;
    static String[] strings;
   
    
    

    
    
    public static void main(String[] args) {
    	int n = input.nextInt();
    	int arr1[][] = new int[n][2];
    	int arr2[][] = new int[n][2];
    	
    	int rep[] = new int[1000001];
    	
    	for (int i = 0; i < n; i++) {
    		int val1 = input.nextInt();
    		int val2 = input.nextInt();
    		
    		if (rep[val1] == 1)
    			rep[val1] = 2;
    		else
    			rep[val1] = -1;
    		

    		if (rep[val2] == -1)
    			rep[val2] = 2;
    		else
    			rep[val2] = 1;	
    		
    		arr1[i][0] = arr2[i][0] = val1;
    		arr1[i][1] = arr2[i][1] = val2;
    	}
    	
    	
    	int ans[] = new int[n];
    	
    	Arrays.sort(arr1, Comparator.comparingInt(a -> a[0]));
    	//Arrays.sort(arr2, Comparator.comparingInt(a -> a[1]));
    	/*
    	for (int i = 0; i < n; i++)
    		System.out.println(Arrays.toString(arr1[i]));
    	
    	for (int i = 0; i < n; i++)
    		System.out.println(Arrays.toString(arr2[i]));
    	*/
    	//System.out.println(Arrays.toString(rep));

    	for (int i = 1; i < 1000001; i++) {
    		if (rep[i] == -1)
    			ans[0] = i;
    		else if (rep[i] == 1)
    			ans[n - 1] = i;
    	}
    
    	//System.out.println(Arrays.toString(ans));
		int val = ans[0];
		int cur = 0;
		//System.out.println(val);
    	while (true) {	
    		int st = 1;
    		int end = n - 1;
    		int val2 = 0;
    		
    		while (st < end) {
    			int mid = (st + end) / 2;
    			int v = arr1[mid][0];

    			if (v == val) {
    				st = mid;
        			//System.out.println(val + " " + val2 + " " + v);
    				break;
    			}
    			else if (v < val)
    				st = mid + 1;
    			else
    		    	end = mid;
            }
    		val2 = arr1[st][1];
    		
        	//System.out.println(val2);

    		cur += 2;
    		if (cur > n - 1)
    			break;
    		
    		//System.out.println(val2);

    		ans[cur] = val2;
    		val = val2;

    	}
    	
    	
    	ans[1] = arr1[0][1];
    	//ans[n - 2] = arr2[0][0];
    	
    	
    	val = ans[1];
		cur = 1;
		while (true) {	
    		int st = 1;
    		int end = n - 1;
    		int val2 = 0;
    		
    		while (st < end) {
    			int mid = (st + end) / 2;
    			int v = arr1[mid][0];

    			if (v == val) {
    				st = mid;
        			//System.out.println(val + " " + val2 + " " + v);
    				break;
    			}
    			else if (v < val)
    				st = mid + 1;
    			else
    		    	end = mid;
            }
    		val2 = arr1[st][1];
    		
        	//System.out.println(val2);

    		cur += 2;
    		if (cur > n - 1)
    			break;
    		
    		//System.out.println(val2);

    		ans[cur] = val2;
    		val = val2;

    	}
    	
    	for (int i = 0; i < ans.length; i++)
    		System.out.print(ans[i] + " ");
    	
    	//.out.println(Arrays.toString(ans));
    }
    	
    
    
    
    
    /*
     * 
     * 4
92 31
0 7
31 0
7 141


0 92 7 31 141 0

odd even 
 . 1 . . 1 .
. 1 . 2 . 1 .


1 2 3 4 5 

5
1 3 > 2
0 2 > 1 
4 0 > 5
3 5 > 4
2 4 > 3

1 2 3 4 5





89 78 124 114 23

0 78
89 124
78 114
124 23
114 0

89 78 124 114 23

rep

89 78  124  114  23


     */
    
    
    
    
    
    
    
    
    
    
    
    
}