#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <fstream>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;
#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define sq5(x) ((x) * (x) * (x) * (x) * (x))
vi p, l, r;
vector<bool> used;
int tmp[4];
vector<vi> g;
queue<int> q,q1;
bool bfs(int v) {
if (used[v]) {
return 1;
}
q.push(v);
while (sz(q)) {
int u = q.front();
q.pop();
if (sz(g[u]) == 3) {
tmp[3] = u;
REP(i, 3) {
tmp[i] = g[u][i];
}
sort(tmp, tmp + 4);
if (tmp[1] == u) {
if (p[u] != -1 && p[u] != tmp[3]) {
return 0;
}
p[u] = tmp[3];
if (l[tmp[3]] != -1 && l[tmp[3]] != u) {
return 0;
}
l[tmp[3]] = u;
if (l[u] != -1 && l[u] != tmp[0]) {
return 0;
}
l[u] = tmp[0];
if (p[tmp[0]] != -1 && p[tmp[0]] != u) {
return 0;
}
p[tmp[0]] = u;
if (r[u] != -1 && r[u] != tmp[2]) {
return 0;
}
r[u] = tmp[2];
if (p[tmp[2]] != -1 && p[tmp[2]] != u) {
return 0;
}
p[tmp[2]] = u;
if (!used[tmp[0]]) {
q.push(tmp[0]);
used[tmp[0]] = 1;
}
if (!used[tmp[2]]) {
used[tmp[2]] = 1;
q.push(tmp[2]);
}
if (!used[tmp[3]]) {
used[tmp[3]] = 1;
q.push(tmp[3]);
}
}
if (tmp[2] == u) {
if (p[u] != -1 && p[u] != tmp[0]) {
return 0;
}
p[u] = tmp[0];
if (r[tmp[0]] != -1 && r[tmp[0]] != u) {
return 0;
}
r[tmp[0]] = u;
if (l[u] != -1 && l[u] != tmp[1]) {
return 0;
}
l[u] = tmp[1];
if (p[tmp[1]] != -1 && p[tmp[1]] != u) {
return 0;
}
p[tmp[1]] = u;
if (r[u] != -1 && r[u] != tmp[3]) {
return 0;
}
r[u] = tmp[3];
if (p[tmp[3]] != -1 && p[tmp[3]] != u) {
return 0;
}
p[tmp[3]] = u;
if (!used[tmp[0]]) {
used[tmp[0]] = 1;
q.push(tmp[0]);
}
if (!used[tmp[1]]) {
used[tmp[1]] = 1;
q.push(tmp[1]);
}
if (!used[tmp[2]]) {
used[tmp[2]] = 1;
q.push(tmp[2]);
}
}
}
if (sz(g[u]) == 2) {
tmp[2] = u;
REP(i, 2) {
tmp[i] = g[u][i];
}
sort(tmp, tmp + 3);
if (tmp[0] == u) {
if (p[u] != -1 && p[u] != tmp[2]) {
return 0;
}
p[u] = tmp[2];
if (l[tmp[2]] != -1 && l[tmp[2]] != u) {
return 0;
}
l[tmp[2]] = u;
if (r[u] != -1 && r[u] != tmp[1]) {
return 0;
}
r[u] = tmp[1];
if (p[tmp[1]] != -1 && p[tmp[1]] != u) {
return 0;
}
p[tmp[1]] = u;
if (!used[tmp[1]]) {
used[tmp[1]] = 1;
q.push(tmp[1]);
}
if (!used[tmp[2]]) {
used[tmp[2]] = 1;
q.push(tmp[2]);
}
}
if (tmp[2] == u) {
if (p[u] != -1 && p[u] != tmp[0]) {
return 0;
}
p[u] = tmp[0];
if (r[tmp[0]] != -1 && r[tmp[0]] != u) {
return 0;
}
r[tmp[0]] = u;
if (l[u] != -1 && l[u] != tmp[1]) {
return 0;
}
l[u] = tmp[1];
if (p[tmp[1]] != -1 && p[tmp[1]] != u) {
return 0;
}
p[tmp[1]] = u;
if (!used[tmp[0]]) {
used[tmp[0]] = 1;
q.push(tmp[0]);
}
if (!used[tmp[1]]) {
used[tmp[1]] = 1;
q.push(tmp[1]);
}
}
if (tmp[1] == u) {
if (p[u] == tmp[0]) {
if (r[u] != -1 && r[u] != tmp[2]) {
return 0;
}
r[u] = tmp[2];
if (p[tmp[2]] != -1 && p[tmp[2]] != u) {
return 0;
}
p[tmp[2]] = u;
if (!used[tmp[2]]) {
used[tmp[2]] = 1;
q.push(tmp[2]);
}
}
if (p[u] == tmp[2]) {
if (l[u] != -1 && l[u] != tmp[0]) {
return 0;
}
l[u] = tmp[0];
if (p[tmp[0]] != -1 && p[tmp[0]] != u) {
return 0;
}
p[tmp[0]] = u;
if (!used[tmp[0]]) {
used[tmp[0]] = 1;
q.push(tmp[0]);
}
}
}
}
}
return 1;
}
vi order;
void InOrder(int v) {
stack<int> st;
while (true) {
while (v != -1) {
st.push(v);
v = l[v];
}
if (v == -1 && sz(st)) {
int top = st.top();
st.pop();
order.pb(top);
v = r[top];
}
if (v == -1 && sz(st) == 0) {
break;
}
}
}
int main(void) {
int n;
scanf("%d", &n);
g.resize(n);
p.resize(n, -1);
l.resize(n, -1);
r.resize(n, -1);
used.resize(n, 0);
REP(i, n - 1) {
int x, y;
scanf("%d%d", &x, &y);
x--, y--;
g[x].pb(y);
g[y].pb(x);
}
REP(i, n) {
if (sz(g[i]) == 3) {
tmp[3] = i;
REP(j, 3) {
tmp[j] = g[i][j];
}
sort(tmp, tmp + 4);
if (tmp[0] == i || tmp[3] == i) {
printf("-1\n");
return 0;
}
q1.push(i);
}
if (sz(g[i]) == 2) {
tmp[2] = i;
REP(j, 2) {
tmp[j] = g[i][j];
}
sort(tmp, tmp + 3);
if (tmp[0] == i || tmp[2] == i) {
q1.push(i);
}
}
}
while (sz(q1)) {
bool ok = bfs(q1.front());
if (!ok) {
printf("-1\n");
return 0;
}
q1.pop();
}
int p1 = -1, p2 = -1;
REP(i, n) {
if (p[i] == -1) {
if (p1 == -1) {
p1 = i;
}
p2 = i;
}
}
bool ok = 1;
if (p2 - p1 > 1) {
FOR(i, p1, p2) {
r[i] = i + 1;
p[i + 1] = i;
}
}
InOrder(p1);
REP(i, sz(order)) {
if (order[i] != i ) {
printf("-1\n");
return 0;
}
}
if (ok) {
FOR(i, p1, p2 + 1) {
printf("%d%c", i + 1, " \n"[i == p2]);
}
}
}
/*
16
1 2
2 3
2 4
4 5
5 6
6 11
11 10
10 9
9 8
8 7
11 16
16 12
12 14
14 13
14 15
*/
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPG1lbW9yeS5oPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8Y3RpbWU+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDxjb21wbGV4PgojaW5jbHVkZSA8c3RkbGliLmg+CiNpbmNsdWRlIDxmc3RyZWFtPgojaW5jbHVkZSA8cmFuZG9tPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHBhaXI8aW50LCBpbnQ+IHBpaTsKdHlwZWRlZiBwYWlyPGRvdWJsZSwgZG91YmxlPiBwZGQ7CnR5cG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