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.util.ArrayList;
import java.util.Scanner;

public class main {

	static int answer = -2;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		Person[] person = new Person[number];
		ArrayList<Integer> answerList1 = new ArrayList<>();
		ArrayList<Integer> answerList2 = new ArrayList<>();
		
		for(int i=0; i<number; i++){
			int front = sc.nextInt();
			int end = sc.nextInt();
			person[i] = new Person(front, end);
		}
		
		new main().mergeSort(person, 0, number-1, true);		// merge sorting
		
		//앞에만 search해주면 된다.
		answer = -2;
		while(true){		// 짝수번째
			int search;
			if(answer == -2){		// 처음 시작
				search = 0;
			}else if(answer == -1){		// 찾는게 없다.
				break;
			}else{
				if(person[answer].back == 0)
					break;
				answerList1.add(person[answer].back);
				search = person[answer].back;
			}

			new main().binarySearch(person, 0, person.length-1, search, true);
		}
		
		//홀수번째
		
		new main().mergeSort(person, 0, number-1, false);		// merge sorting\
		
		// 맨첫번쨰꺼 찾자
		answer = -2;		// 초기화
		int search= 0;
		for(int i=0; i<person.length; i++){
			search = person[i].front;
//			System.out.println(search);
			new main().binarySearch(person, 0, person.length-1, search, false);		// 뒤에거로
			if(answer == -1){
				break;
			}
		}
//		System.out.println(" : "+search);
		new main().mergeSort(person, 0, number-1, true);		// merge sorting
		answer = -2;
		answerList2.add(search);
		while(true){		// 홀수번째
			if(answer == -2){		// 처음 시작
				search = answerList2.get(0);
			}else if(answer == -1){		// 찾는게 없다.
				break;
			}else{
				if(person[answer].back == 0)
					break;
				answerList2.add(person[answer].back);
				search = person[answer].back;
			}

			new main().binarySearch(person, 0, person.length-1, search, true);
		}
		
		int i =0;
		int j=0;
		while(true){
			if(i == answerList2.size() && j == answerList1.size())
				break;
			if(i<answerList2.size())
				System.out.print(answerList2.get(i++) + " ");
			if(j<answerList1.size())
				System.out.print(answerList1.get(j++) + " ");
			
		}
		
	}
	void binarySearch(Person[] person, int start, int end, int search, boolean isFront){
		if(answer != -2 && search == 0)
			return;
		if(start>end ){
			answer = -1;
			return;
		}
		
		int mid = (start+end)/2;
		if(person[mid].getData(isFront) == search){
			answer = mid;
			return;
		}else if(person[mid].getData(isFront) > search){
			binarySearch(person, start, mid-1, search,isFront);
		}else{
			binarySearch(person,mid+1, end, search,isFront);
		}
	}
	
	void mergeSort(Person[] person, int start, int end, boolean isFront){
		
		if(start >= end){		// 탈출 조건
			return;
		}else{
			int mid = (start+end)/2;
			mergeSort(person, start, mid, isFront);
			mergeSort(person, mid+1, end, isFront);
			
			int m = start;
			int n = mid+1;
			Person[] temp = new Person[end-start+1];
			//merge
			for(int i=0; i<end-start+1; i++){
				if(m>mid){	
					temp[i] = person[n++];
				}else if(n>end){
					temp[i] = person[m++];
				}else if(person[m].getData(isFront)>person[n].getData(isFront)){
					temp[i] = person[n++];
				}else if(person[m].getData(isFront)<= person[n].getData(isFront)){
					temp[i] = person[m++];
				}
			}
			
			for(int i=0; i<end-start+1; i++)
				person[start+i] = temp[i];
		}
		
	}
}

class Person{
	int front;
	int back;
	boolean isCheck;
	public Person(int front, int end){
		this.front = front;
		this.back = end;
		isCheck = false;
	}
	public int getData(boolean isFront){
		if(isFront)
			return front;
		else 
			return back;
	}
	@Override
	public String toString() {
		return "Person [front=" + front + ", back=" + back + "]";
	}
}