#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

class Tree{
public:
   int N;
   vector<int> parent;
   vector<vector<int> > child;
   
   Tree():N(0){};
   Tree(int n):N(n){
      parent.resize(N+1,-1);
      child.resize(N);
   }
   
   void print(){
      for(int i=0; i<N+1; i++){
         if(parent[i] != -1)
            printf("%d\n",parent[i]);
      }
   }
};

class Graph{
public:
   int N;
   vector<vector<int> > adj;
   
   Graph():N(0){};
   Graph(int n):N(n){adj.resize(N+1);}
   
   void addNode(int x, int y){
      adj[x].push_back(y);
      adj[y].push_back(x);
   }
   
   void sortNode(){
      for(int i=0; i<N+1; i++)
         sort(adj[i].begin(), adj[i].end());
   }
   
   Tree makeTree(int root){
      Tree T(N+1);
      queue<int> q;
      vector<bool> check(N,false);
      
      q.push(root);
      check[root] = true;
      
      while(!q.empty()){
         int cur = q.front();
         q.pop();
         
         for(int next : adj[cur]){
            if(check[next] == false){
               check[next] = true;
               q.push(next);
               T.parent[next] = cur;
               T.child[cur].push_back(next);
            }
         }
      }
      return T;
   }
};


int main() {
   
   int n;
   scanf("%d",&n);
   
   Graph G(n);
   for(int i=0; i<n; i++){
      int a,b;
      scanf("%d %d",&a,&b);
      G.addNode(a,b);
   }
   G.sortNode();
   Tree T = G.makeTree(1);
   T.print();
   
   return 0;
}