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.math.BigInteger;
    import java.text.DecimalFormat;
    import java.util.*;
     
    //import Submatrix.InputReader;
         
         
         
         public class Main {
        	public static InputReader in;
            public static PrintWriter pw;
         
         
         
        	public static void main(String args[]) {
        		new Thread(null, new Runnable() {
                    public void run() {
                        try{
                            solve();
                        }
                        catch(Exception e){
                            e.printStackTrace();
                        }
                    }
                }, "1", 1 << 26).start();
            }
        	static ArrayList<Integer> g[];
        	static ArrayList<Integer> h[];
        	static boolean visited[];
        	static boolean visit[];
        	static int par[];
        	static int degree[];
        	static int edjes=0;
        	static int start=-1;
        	static int end=-1;
        	static int Total=0;
        	static int time1[];
        	static int time2[];
        	static int glob=0;
        	static long ans[]=new long[1000000];
        	static boolean vis2[][];
        	//static long sum1=0;
        	//static long val[];
            static ArrayList<Integer> levels[];
            static int max=0;
            static int lev=1;
            static ArrayList<Integer> nodes[];
            static ArrayList<Integer> values[];
            static int depth[];
            static boolean found=false;
           // static long sm[];
            static int sum1=0;
            static int pre[][];
            static int subtree[];
           static  int cnt=0;
           static  HashMap<String,Integer> hm;
           static int sm[];
           static int prime[];
           static long mul[];
           static long d[]=new long[1000000];
           static int tot=0;
           static long highest=(long)1e9;
           static int count=0;
            static Stack<Integer> tt=new Stack();
            static long Cardinality[];
            static int k;
            public static void solve(){
        		
        	
        		 in = new InputReader(System.in);
        		 pw = new PrintWriter(System.out);
                 int n=in.nextInt();
                 int a[]=new int[n];
                 int b[]=new int[n];
                 int fr[]=new int[1000001];
                 int fr1[]=new int[1000001];
                 int c[]=new int[1000001];
                 int prev[]=new int[1000002];
                 int next[]=new int[1000002];
                 HashMap<Integer,Integer> hm=new HashMap();
                 HashMap<Integer,Integer> hm2=new HashMap();
                  for(int i=0;i<n;i++)
                 {
                	 a[i]=in.nextInt();
                	 b[i]=in.nextInt();
                	 hm.put(b[i],i);
                	 hm2.put(a[i],i);
                	 prev[i]=a[i];
                	 next[i]=b[i];
                	 c[a[i]]++;
                	 c[b[i]]++;
                	 fr[a[i]]++;
                	 fr1[b[i]]++;
                 }
                  int frnt=-1;
                  for(int i=1;i<=1000000;i++)
                  {
                	  if(fr[i]==1&&c[i]==1){
                		  frnt=i;break;
                	  }
               }
                  int rear=-1;
                  for(int i=1;i<=1000000;i++)
                  {
                	  if(fr1[i]==1&&c[i]==1){
                		  rear=i;break;
                	  }
                  }
                  
                  int ans[]=new int[n];
                  ans[0]=frnt;
                  ans[n-1]=rear;
                  for(int i=n-1;i>=2;i-=2)
                  {
                	  int index=hm.get(ans[i]);
                	  ans[i-2]=a[index];
                  }
                  for(int i=0;i<n;i++)
                  {
                	  if(a[i]==0)
                	  {
                		  ans[1]=b[i];
                		  break;
                	  }
                  }
                  for(int i=0;i<n;i++)
                  {
                	 if(ans[i]==0)
                	 {
                		 int index=hm2.get(ans[i-2]);
                		 ans[i]=b[index];
                	 }
                  }
                  for(int i=0;i<n;i++)
                	  System.out.print(ans[i]+" ");
            }

             static class Pair implements Comparable<Pair>{
            	int now;
            		int aft;
            		//int index;
            		Pair(int ver,int weight){
            	     	this.now=ver;
            			this.aft=weight;
            			//this.index=index;
            			
            		}
            		@Override
            		public int compareTo(Pair o) {
                            
            				return (int)(o.now-now);
            		}
            				
            	}
        	static class InputReader {
         
        		private InputStream stream;
        		private byte[] buf = new byte[8192];
        		private int curChar, snumChars;
        		private SpaceCharFilter filter;
         
        		public InputReader(InputStream stream) {
        			this.stream = stream;
        		}
         
        		public int snext() {
        			if (snumChars == -1)
        				throw new InputMismatchException();
        			if (curChar >= snumChars) {
        				curChar = 0;
        				try {
        					snumChars = stream.read(buf);
        				} catch (IOException e) {
        					throw new InputMismatchException();
        				}
        				if (snumChars <= 0)
        					return -1;
        			}
        			return buf[curChar++];
        		}
         
        		public   int nextInt() {
        			int c = snext();
        			while (isSpaceChar(c))
        				c = snext();
        			int sgn = 1;
        			if (c == '-') {
        				sgn = -1;
        				c = snext();
        			}
        			int res = 0;
        			do {
        				if (c < '0' || c > '9')
        					throw new InputMismatchException();
        				res *= 10;
        				res += c - '0';
        				c = snext();
        			} while (!isSpaceChar(c));
        			return res * sgn;
        		}
         
        		public long nextLong() {
        			int c = snext();
        			while (isSpaceChar(c))
        				c = snext();
        			int sgn = 1;
        			if (c == '-') {
        				sgn = -1;
        				c = snext();
        			}
        			long res = 0;
        			do {
        				if (c < '0' || c > '9')
        					throw new InputMismatchException();
        				res *= 10;
        				res += c - '0';
        				c = snext();
        			} while (!isSpaceChar(c));
        			return res * sgn;
        		}
         
        		public int[] nextIntArray(int n) {
        			int a[] = new int[n];
        			for (int i = 0; i < n; i++)
        				a[i] = nextInt();
        			return a;
        		}
         
        		public String readString() {
        			int c = snext();
        			while (isSpaceChar(c))
        				c = snext();
        			StringBuilder res = new StringBuilder();
        			do {
        				res.appendCodePoint(c);
        				c = snext();
        			} while (!isSpaceChar(c));
        			return res.toString();
        		}
         
        		public boolean isSpaceChar(int c) {
        			if (filter != null)
        				return filter.isSpaceChar(c);
        			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        		}
         
        		public interface SpaceCharFilter {
        			public boolean isSpaceChar(int ch);
        		}
        	}
        }