{TL-решение задачи ОЧЕРЕДЬ.}
{Сложность - O(n^2).}

program queue2;
    var  i, j, n : integer;
            k, t : integer;
            a, b : array[1..200000] of integer;

begin
     assign(input,   'queue.in'); reset(input);
     assign(output, 'queue.out'); rewrite(output);
     readln(n);

     for i := 1 to n-1 do read(a[i], b[i]);
     for i := 1 to n-1 do begin
         k := 0;
         for j := 1 to n-1 do
             if a[i] = b[j] then inc(k);
         if k = 0 then begin write(a[i], ' ', b[i]); t := b[i]; end;
     end;

     for i := 1 to n-2 do
         for j := 1 to n-1 do
             if t = a[j] then begin write(' ',b[j]); t := b[j]; end;
     close(input);
     close(output);
end.