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:
//package com.company;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {

    public static void main(String[] args) throws IOException {
        // write your code here
       Scanner s = new Scanner(System.in);
         // BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
    int n=s.nextInt();ArrayList<Integer> [] seedha=new ArrayList[1000001];ArrayList<Integer> [] ulta=new ArrayList[1000001];ArrayList<Integer> hi=new ArrayList<Integer>();
        HashMap<Integer,Integer> hi1=new HashMap<Integer, Integer>();
    int v=0; for(int i=0;i<n;i++){
        int x=s.nextInt();int y=s.nextInt();
        hi1.put(x,1);
        hi.add(y);
        if(seedha[x]==null) seedha[x]=new ArrayList<Integer>();
        if(ulta[y]==null) ulta[y]=new ArrayList<Integer>();
        //v=y;
        seedha[x].add(y);ulta[y].add(x);
    }
    int[] a=new int[n];
    int i=1;int x=0;int[] vis=new int[1000001];vis[x]=1;
    while(seedha[x]!=null){
              if(seedha[x].get(0)==00 ) break;
        a[i]=seedha[x].get(0);x=a[i];i+=2;vis[x]=1;
    }
    if(seedha[x]!=null&&seedha[x].get(0)==0){
        for(Integer j:hi){
            if(vis[j]==0&&!hi1.containsKey(j)) {
                v=j;break;
            }
        }i=n-1;
      //  System.out.println(v);
        while(i>=0){
            a[i]=v;
            if(ulta[v]==null) break;
            v=ulta[v].get(0);i-=2;
        }
    }else{
        i=n-2;
        while(i>=0){
            a[i]=ulta[v].get(0);
            v=a[i];i-=2;
        }
    }
    for(i=0;i<n;i++)
        sb.append(a[i]+" ");
        System.out.println(sb.toString());
    }



    static double power(double x, long y, int p)
    {
        double res = 1;
 x = x % p;
        while (y > 0)
        {
            if((y & 1)==1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }
    static int m;
    static int n;
    static int path = Integer.MAX_VALUE;
    static int got = 0;
static Long[] sum;static Long[] a;
    public static long dfs(int i, ArrayList<Integer>[] h, int[] vis) {
        vis[i] = 1;
        sum[i]+=a[i];if(h[i]==null) return sum[i];
        for (Integer j : h[i]) {
            if (vis[j] == 0) {
                sum[i]+=dfs(j, h, vis);
            }
        }return sum[i];
    }static long max=Long.MIN_VALUE;static long max1=Long.MIN_VALUE;
    public static void dfs1(int i, ArrayList<Integer>[] h, int[] vis) {
        vis[i] = 1;//sum[i]+=a[i];
        if(h[i]==null) return ;
        for (Integer j : h[i]) {
            if (vis[ j] == 0) {
                if(sum[j]>max) {max1=max;max=sum[j];}
                else if(sum[j]>max1) max1=sum[j];
                dfs1(j, h, vis);
            }
        }return ;
    }static long fans=Long.MIN_VALUE;
    public static long dfs2(int i, ArrayList<Integer>[] h, int[] vis) {
        long max2=Long.MIN_VALUE;long max3=Long.MIN_VALUE;
        vis[i] = 1;if(h[i]==null) return a[i];
        for (Integer j : h[i]) {
            if (vis[ j] == 0) {
              long k=  dfs2(j, h, vis);
              if(k>max2) { max3=max2;max2=k;}
              else if(k>max3) max3=k;
            }
        }
     //   System.out.println(i+" "+max2+" "+max3+" "+sum[i]);
        if(max2!=Long.MIN_VALUE&&max3!=Long.MIN_VALUE&&max2+max3> fans) fans=max2+max3;
     //   if(i==1) return max2;
        return Math.max(sum[i],max2);
    }

    public static void bfs(int i, HashMap<Integer, Integer>[] h, int[] vis, int len, int papa) {
        Queue<Integer> q = new LinkedList<Integer>();
        q.add(i);

    }


    static int i(String a){
        return Integer.parseInt(a);
    }static long l(String a){
        return Long.parseLong(a);
    }static String[] inp() throws IOException{
        BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
        return s.readLine().trim().split("\\s+");
    }
}

class Student
{
 int t,l,r;
//    String name, address;

    // Constructor
    public Student(int t,int r)
    {this.t=t;

        this.r=r;
    }

    // Used to print student details in main()
    public String toString()
    {
        return this.t + " " +this.l+" "+this.r;
    }
}

class Sortbyroll implements Comparator<Student>
{
    // Used for sorting in ascending order of
    // roll number
    public int compare(Student a, Student b)
    {
        return a.t-b.t;
    }
}