n,i,j,x,y,s1,s2:longint;
begin
readln(n);
for i:=1 to n-1 do
begin
readln(x,y);
a[y]:=x;
end;
readln(x,y);
b[1]:=x;
s1:=1;
while x<>0 do
begin
s1:=s1+1;
b[s1]:=a[x];
x:=a[x];
end;
c[1]:=y;
s2:=1;
while y<>0 do
begin
s2:=s2+1;
c[s2]:=a[y];
y:=a[y];
end;
if s1<s2
then begin
for i:=1 to s1 do
for j:=1 to s2 do
if b[i]=c[j]
then begin
writeln(b[i]);
halt;
end;
end
else begin
for i:=1 to s2 do
for j:=1 to s1 do
if c[i]=b[j]
then begin
writeln(c[i]);
halt;
end;
end;
end.