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.BufferedInputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


@SuppressWarnings("unused")
public final class Main {

	public static void main(String[] args) throws IOException {

//		long startTime = new Date().getTime();
		
		InputReader in = new InputReader(System.in);
//		InputReader in = new InputReader(new FileInputStream(new File("inputs/simple.in")));
		
		PrintWriter writer = new PrintWriter(System.out);
//		PrintWriter writer = new PrintWriter("outputs/simple.out");

		solveTheProblem(in, writer);
		
//		long endTime = new Date().getTime();
//		System.err.println("Time: " + (endTime - startTime) + " millis");
		
	}

	public static void solveTheProblem(InputReader in, PrintWriter writer) throws IOException {

		int N = in.ni();
		
		int[][] st = new int[N+1][2];
		for (int i = 1; i <= N; i++)
			st[i] = new int[] { in.ni(), in.ni() };
		
		int[] infront = new int[1000001];
		int[] behind = new int[1000001];
		for (int i = 1; i <= N; i++) {
			infront[st[i][1]] = st[i][0];
			behind[st[i][0]] = st[i][1];
		}
		
		int odd = behind[0];
		
		boolean found = false;
		int even = -1; int aux = 0;
		while (!found) {
			even = st[aux++][0];
			if (even != 0) {
				while (infront[even] != 0)
					even = infront[even];
				if (even != odd)
					found = true;
			}
		}
		
		while (odd != 0) {
			writer.println(even);
			writer.println(odd);
			odd = behind[odd];
			even = behind[even];
		}
		if (N % 2 == 1)
			writer.println(even);
		
		// don't forget partial flushes!
		writer.flush();
		
	}
	
	/** Utils **/

	private static final long MOD = (long) Math.pow(10, 9)+7;

	private static long mod(long n) {
		return n % MOD;
	}
	
	private static int pow(int n, int p) {
		return (int) Math.pow(n, p);
	}

	private static long pow(long n, long p) {
		return (long) Math.pow(n, p);
	}
	
	private static class BIT {
		
		private int n;
		private long[] freqs;
		private long[] cumulativeFreqs;
		
		public BIT(int n) {
			this.n = n;
			this.freqs = new long[n];
			this.cumulativeFreqs = new long[n];
		}
		
		public void add(int idx, long v) {
			
			this.freqs[idx] = mod(this.freqs[idx] + v);
			
			int i = idx;
			while (i < n) {
				
				this.cumulativeFreqs[i] = mod(this.cumulativeFreqs[i] + v);
				
				int lastDigit = i & -i;
				i += lastDigit;
				
			}
			
		}
		
		public long getCumulativeSum(int idx) {
			
			long ans = 0;
			
			int i = idx;
			while (i > 0) {
				
				ans = mod(ans + this.cumulativeFreqs[i]);
				
				int lastDigit = i & -i;
				i -= lastDigit;
				
			}
			
			return ans;
		}
		
	}
	
	private static String joinWithSpaces(Object... a) {
		StringBuilder str = new StringBuilder();
		if (a.length > 0) {
			str.append(a[0]);
			for (int i = 1; i < a.length; i++) {
				str.append(' ');
				str.append(a[i]);
			}
		}
		return str.toString();
	}

	private static String joinWithSpaces(long[] a) {
		StringBuilder str = new StringBuilder();
		if (a.length > 0) {
			str.append(a[0]);
			for (int i = 1; i < a.length; i++) {
				str.append(' ');
				str.append(a[i]);
			}
		}
		return str.toString();
	}
	
    private static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }
    
    private static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }
    
    private static boolean[] createPrimeSieve(int n) {
        boolean[] sieve = new boolean[n+1];
        Arrays.fill(sieve, true);
        for (int i = 2; i <= n; i++) {
            if (sieve[i]) {
                for (int j = i+i; j <= n; j += i)
                    sieve[j] = false;
            }
        }
        return sieve;
    }
    
    private static int countPrimes(boolean[] sieve) {
        int ans = 0;
        for (int i = 2; i < sieve.length; i++)
            if (sieve[i]) ans++;
        return ans;
    }

	public static class InputReader implements Closeable {
		
//		private InputStream in;
		private Scanner in;
		private StringBuilder sb = new StringBuilder();
		
//		public InputReader(File file) throws FileNotFoundException {
//			this(new FileInputStream(file));
//		}
//		
//		public InputReader(InputStream wrapped) {
//			this.in = new BufferedInputStream(wrapped);
//		}

		public InputReader(InputStream wrapped) {
			this.in = new Scanner(wrapped);
		}
		
		@Override
		public void close() throws IOException {
			this.in.close();
		}

		public int ni() throws IOException {
//			sb.setLength(0);
//		mainloop:
//			for (;;) {
//				int b = this.in.read();
//				while (b == -1 || !((b >= '0' && b <= '9') || b == '-')) {
//					if (sb.length() > 0) break mainloop;
//					else b = this.in.read();
//				}
//				sb.append((char) b);
//			}
//			return new Integer(sb.toString());
			return in.nextInt();
		}

		public String nstr() throws IOException {
//			sb.setLength(0);
//			int ans = 0;
//		mainloop:
//			for (;;) {
//				int b = this.in.read();
//				while (b == -1 || !((b >= 'a' && b <= 'z') || (b >= 'A' && b < 'Z'))) {
//					if (sb.length() > 0) break mainloop;
//					else b = this.in.read();
//				}
//				sb.append((char) b);
//			}
//			return sb.toString();
			return in.next();
		}
		
		public long nl() throws IOException {
			return in.nextLong();
		}
		
		public char[] nca(int n) throws IOException {
			char[] ca = new char[n];
			String str = nstr();
			for (int i = 0; i < n; i++)
				ca[i] = str.charAt(i);
			return ca;
		}
		
	}
	
}