Problem: One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B», they stamp it with «A B», or «B A». Unfortunately, often it is impossible to send a letter directly from the city of the sender to the city of the receiver, that's why the letter is sent via some intermediate cities. Post officers never send a letter in such a way that the route of this letter contains some city more than once. Bob is sure that the post officers stamp the letters accurately.

There are n stamps on the envelope of Bob's letter. He understands that the possible routes of this letter are only two. But the stamps are numerous, and Bob can't determine himself none of these routes. That's why he asks you to help him. Find one of the possible routes of the letter.

Input

The first line contains integer n (1 ≤ n ≤ 105) — amount of mail stamps on the envelope. Then there follow n lines with two integers each — description of the stamps. Each stamp is described with indexes of the cities between which a letter is sent. The indexes of cities are integers from 1 to 109. Indexes of all the cities are different. Every time the letter is sent from one city to another, exactly one stamp is put on the envelope. It is guaranteed that the given stamps correspond to some valid route from some city to some other city. 

Output

Output n + 1 numbers — indexes of cities in one of the two possible routes of the letter.

Examples

Input

2
1 100
100 2


Output

2 100 1 

Input

3
3 1
100 2
3 2


Output

100 2 3 1 

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        CMailStamps solver = new CMailStamps();
        solver.solve(1, in, out);
        out.close();
    }

    static class CMailStamps {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n;
            HashMap<Integer, Node> hm = new HashMap<>();
            HashMap<Integer, Boolean> vis = new HashMap<>();
            n = in.nextInt();
            for (int i = 0; i < n; i++) {
                int a = in.nextInt(), b = in.nextInt();
                Node node_a, node_b;
                if (!hm.containsKey(a)) {
                    node_a = new Node(a);
                    hm.put(a, node_a);
                } else node_a = hm.get(a);
                if (!hm.containsKey(b)) {
                    node_b = new Node(b);
                    hm.put(b, node_b);
                } else node_b = hm.get(b);
                if (node_a.first == -1) {
                    node_a.first = b;
                    if (node_b.first == -1) {
                        node_b.first = a;
                    } else {
                        node_b.second = a;
                    }
                } else {
                    node_a.second = b;
                    if (node_b.first == -1) {
                        node_b.first = a;
                    } else {
                        node_b.second = a;
                    }
                }
                node_a.degree++;
                node_b.degree++;
                if (!vis.containsKey(a)) vis.put(a, false);
                if (!vis.containsKey(b)) vis.put(b, false);
            }
            int start = -1;
            for (Map.Entry<Integer, Node> entry : hm.entrySet()) {
                if (entry.getValue().degree == 1) {
                    start = entry.getKey();
                    break;
                }
            }
            vis.put(start, true);
            ArrayList<Integer> al = new ArrayList<>();
            al.add(start);
            int curr = hm.get(start).first;
            while (hm.get(curr).degree != 1) {
                vis.put(curr, true);
                al.add(curr);
                int a = hm.get(curr).first;
                int b = hm.get(curr).second;
                if (vis.get(a)) curr = b;
                else curr = a;
            }
            al.add(curr);
            for (int x : al) out.printsc(x);
            out.println();
            out.flush();
        }

        class Node {
            int val;
            int degree;
            int first;
            int second;

            private Node(int val) {
                first = -1;
                second = -1;
                degree = 0;
                this.val = val;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(FileInputStream file) {
            this.stream = file;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = (res << 3) + (res << 1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;
        private ArrayList<String> res = new ArrayList<>();
        private StringBuilder sb = new StringBuilder("");

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void println(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                sb.append(objects[i]);
            }
            res.add(sb.toString());
            sb = new StringBuilder("");
        }

        public void printsc(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                sb.append(objects[i]).append(' ');
            }
        }

        public void close() {
//        writer.flush();
            writer.close();
        }

        public void flush() {
            for (String str : res) writer.printf("%s\n", str);
            res.clear();
            sb = new StringBuilder("");
        }

    }
}