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

public class CodeForces {
    /*****************************************WRITING CODE STARTS HERE******************************************/
    public static void solve(int t)throws IOException {
        int n = sc.nextInt();
        Map<Integer,Integer> next = new HashMap<>();
        Map<Integer,Integer> count = new HashMap<>();
        int [] first = new int[n];
        int[] second = new int[n];
        for(int i=0;i<n;i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            first[i] = x;
            second[i]= y;
            next.put(x,y);
            count.put(x,count.getOrDefault(x,0)+1);
            count.put(y,count.getOrDefault(y,0)+1);
        }
        int start = -1;
        int end = -1;
        for(int i=0;i<n;i++){
            if(count.get(first[i]) == 1)start = first[i];
            if(count.get(second[i]) == 1)end = second[i];
        }
        Map<Integer,Integer> ans = new HashMap<>();
        ans.put(1,start);
        ans.put(n,end);
        int curr = start;
        int currIndex = 1;
        while (next.containsKey(curr) && curr != end){
            curr = next.get(curr);
            currIndex+=2;
            ans.put(currIndex,curr);
        }
        curr = next.get(0);
        currIndex=2;
        ans.put(currIndex,curr);
        while (next.containsKey(curr) && next.get(curr)!=0){
            curr = next.get(curr);
            currIndex+=2;
            ans.put(currIndex,curr);
        }
        for(int i=1;i<=n;i++)out.print(ans.get(i)+" ");
    }


    /*****************************************WRITING CODE ENDS HERE******************************************/

    public static void main(String[] args) throws IOException{
        int testCase = 1;
//        testCase = sc.nextInt();
        for (int i = 1; i <= testCase; i++) solve(i);
        closeIO();

    }
    static FastestReader sc = new FastestReader();              // FASTEST INPUT
    static PrintWriter out = new PrintWriter(System.out);                // FAST OUTPUT


    /**************************************HELPER FUNCTION STARTS HERE ************************************/

    public static int mod = (int) 1e9 + 7;
    public static final int inf_int = (int) 1e9;
    public static final long inf_long = (long) 1e12;

    public static final String YES = "Yes";
    public static final String NO = "No";

    public static void sort(int[] a, boolean isAscending) {
        ArrayList<Integer> temp = new ArrayList<>();
        for (int j : a) temp.add(j);
        sort(temp, isAscending);
        for (int i = 0; i < a.length; i++) a[i] = temp.get(i);
    }

    public static void sort(long[] a, boolean isAscending) {
        ArrayList<Long> temp = new ArrayList<>();
        for (long ele : a) temp.add(ele);
        sort(temp, isAscending);
        for (int i = 0; i < a.length; i++) a[i] = temp.get(i);
    }
    @SuppressWarnings({"rawtypes","unchecked"})
    public static void sort(List list, boolean isAscending) {
        if (isAscending) Collections.sort(list);
        else list.sort(Collections.reverseOrder());
    }

    // count the length of a number, time O(1)
    public static int countDigitBase10(long n) {
        if (n == 0) return 0;
        return (int) (1 + Math.log10(n));
    }

    // euclidean algorithm
    public static long gcd(long a, long b) {
        // time O(max (loga ,logb))
        long x = Math.min(a, b);
        long y = Math.max(a, b);
        if (y % x == 0) return x;
        return gcd(y % x, x);
    }

    public static long lcm(long a, long b) {
        // lcm(a,b) * gcd(a,b) = a * b
        return (a / gcd(a, b)) * b;
    }
    // binary exponentiation
    public static long power(long x, long n) {
        // time O(logn)
        long ans = 1;
        while (n > 0) {
            if ((n & 1) == 1) {
                ans *= x;
                ans %= mod;
                n--;
            } else {
                x *= x;
                x %= mod;
                n >>= 1;
            }
        }
        return ans;
    }

    public static long firstDivisor(long n) {
        if (n == 1 || n == 0) return n;
        for (long i = 2; i * i <= n; i++)
            if (n % i == 0) return i;
        return -1;
    }

    public static long max3(long a, long b, long c) {
        return max2(max2(a, b), c);
    }

    public static long max2(long a, long b) {
        return Math.max(a, b);
    }

    public static long min3(long a, long b, long c) {
        return min2(min2(a, b), c);
    }

    public static long min2(long a, long b) {
        return Math.min(a, b);
    }

    public static int max3(int a, int b, int c) {
        return max2(max2(a, b), c);
    }

    public static int max2(int a, int b) {
        return Math.max(a, b);
    }

    public static int min3(int a, int b, int c) {
        return min2(min2(a, b), c);
    }

    public static int min2(int a, int b) {
        return Math.min(a, b);
    }

    /**************************************HELPER FUNCTION ENDS HERE ************************************/

    /*****************************************FAST INPUT STARTS HERE *************************************/


    public static void closeIO() throws IOException{
            out.flush();
            out.close();
            sc.close();
    }
    private static class FastestReader {
        private static final int BUFFER_SIZE = 1 << 16;
        private final DataInputStream din;
        private final byte[] buffer;
        private int bufferPointer, bytesRead;

        public FastestReader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public FastestReader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }

        private int skip() throws IOException {
            int b;
            //noinspection StatementWithEmptyBody
            while ((b = read()) != -1 && isSpaceChar(b)) {}
            return b;
        }

        public String next() throws IOException {
            int b = skip();
            final StringBuilder sb = new StringBuilder();
            while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            final boolean neg = c == '-';
            if (neg) { c = read(); }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg) { return -ret; }
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ') { c = read(); }
            final boolean neg = c == '-';
            if (neg) { c = read(); }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) { return -ret; }
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') { c = read(); }
            final boolean neg = c == '-';
            if (neg) { c = read(); }

            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg) { return -ret; }
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) { buffer[0] = -1; }
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead) { fillBuffer(); }
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            din.close();
        }

    }
    /*****************************************FAST INPUT ENDS HERE *************************************/
}