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.util.*;

import javax.naming.BinaryRefAddr;

public class b {
	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public class c implements Comparable<c> {
		int pr, nx;

		public c(int pr, int nx) {
			this.pr = pr;
			this.nx = nx;
		}

		public int compareTo(c o) {
			return pr == o.pr ? nx - o.nx : pr - o.pr;
		}
	}

	public int bin(int l, int r, int t) {
		// System.out.println(l+" "+r);
		if (l == r) {
			return l;
		}
		int m = (l + r) / 2;
		if (t <= a[m].pr) {
			return bin(l, m, t);
		} else {
			return bin(m + 1, r, t);
		}
	}

	public c a[];

	public void solve() throws IOException {
		int n = nextInt();
		int max = 1000001;
		int pos[] = new int[max];
		a = new c[n];
		for (int i = 0; i < n; i++) {
			a[i] = new c(nextInt(), nextInt());
			pos[a[i].nx]++;
			pos[a[i].pr]++;
		}
		Arrays.sort(a);
		int st = -1;
		int fin = -1;
		for (int i = 0; i < max; i++) {
			if (pos[i] == 1) {
				if (st == -1) {
					st = i;
				} else {
					fin = i;
				}
			}
		}
		// first half
		ArrayList<c> q = new ArrayList<c>();
		q.add(a[0]);
		int t = a[0].nx;
		int kol1 = (n - 1) / 2;
		int j = 0;
		for (int i = 0; i < kol1; i++) {
			j = bin(0, n - 1, t);
			q.add(a[j]);
			t = a[j].nx;
		}
		kol1++;
		// for (int i = 0; i < q.size(); i++) {
		// out.print(q.get(i).pr + " " + q.get(i).nx + " ");
		// }
		// out.println();
		// second half
		// out.println(st+" "+fin);
		ArrayList<c> w = new ArrayList<c>();
		for (int i = 0; i < n; i++) {
			if (a[i].pr == st) {
				t = a[i].nx;
				w.add(a[i]);
				break;
			}
			if (a[i].pr == fin) {
				t = a[i].nx;
				w.add(a[i]);
				break;
			}
		}
		int kol2 = n - kol1 - 1;
		// out.println(w.size());
		// System.out.println("next");
		for (int i = 0; i < kol2; i++) {
			j = bin(0, n - 1, t);
			w.add(a[j]);
			t = a[j].nx;
		}
		// w.add(a[j]);
		// for (int i = 0; i < w.size(); i++) {
		// out.print(w.get(i).pr + " " + w.get(i).nx + " ");
		// }
		j = 1;
		int e = 0;
		while (j < q.size() || e < w.size()) {
			if (e < w.size()) {
				out.print(w.get(e).pr + " ");
				e++;
			}
			if (j < q.size()) {
				out.print(q.get(j).pr + " ");
				j++;
			}
		}
		if (n % 2 == 0) {
			out.print(q.get(q.size() - 1).nx);
		} else {
			out.print(w.get(w.size() - 1).nx);

		}
	}

	public void run() throws IOException {

		// br = new BufferedReader(new FileReader(new File("")));
		// out = new PrintWriter("");
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();

		br.close();
		out.close();

	}

	public static void main(String[] args) throws IOException {
		new b().run();

	}
}