#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<set>
#include<algorithm>
#define maxn 10010
using namespace std;
vector<int> g[maxn];
int N;
bool visit[maxn];
int dfs(int a) {
visit[a] = true;
int m = 0;
for (int i = 0; i < g[a].size(); i++) {
int t = g[a][i];
if (visit[t] == false) {
visit[t] = true;
int n = dfs(t);
if (n > m) m = n;
}
}
return m + 1;
}
int main() {
fill(visit, visit + maxn, false);
int a, b;
scanf("%d", &N);
for (int i = 0; i < N - 1; i++) {
scanf("%d %d", &a, &b);
g[a].push_back(b);
g[b].push_back(a);
}
int c = 0;
for (int i = 1; i <= N; i++) {
if (visit[i] == false) {
dfs(i);
c++;
}
}
if (c > 1) printf("Error: %d components", c);
else {
set<int> se;
int m = 0;
for (int i = 1; i <= N; i++) {
fill(visit, visit + maxn, false);
a = dfs(i);
if (a > m) {
se.clear();
se.insert(i);
m = a;
}
else if (a == m) se.insert(i);
}
for (set<int>::iterator it = se.begin(); it != se.end(); it++) {
printf("%d\n", *it);
}
}
return 0;
}