10
4 2
7 4
2 6
2 5
4 8
10 3
2 9
9 1
5 10
 10
5 10
7 8
8 3
2 6
3 2
9 7
4 5
10 1
6 4
 4
4 1
4 3
4 2
 3
3 1
1 2
 9
1 2
1 3
1 4
1 5
1 6
6 7
6 8
8 9
 5
1 5
2 3
2 4
1 2
 8
6 1
4 7
4 8
8 5
7 6
4 3
4 2
 7
5 6
5 7
5 1
7 4
6 3
3 2
 3
1 3
3 2
 2
1 2
 5
5 4
4 3
3 1
5 2
 6
1 6
3 1
6 4
5 3
2 5
 11
8 9
2 7
1 11
3 2
9 1
8 5
8 6
5 4
4 10
8 3
 11
11 9
6 7
7 1
8 11
5 6
3 5
9 3
10 8
2 4
4 10
 12
12 6
6 7
8 11
4 8
10 4
12 3
2 10
6 2
12 9
4 1
9 5

-1
 9
 1
 1
 3
 3
 -1
 -1
 1
 1
 1
 5
 1
 5
 -1

#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
inline int readChar();
template <class T = int>
inline T readInt();
template <class T>
inline void writeInt(T x, char end = 0);
inline void writeChar(int x);
inline void writeWord(const char *s);
static const int buf_size = 4096;
inline int getChar() {
  static char buf[buf_size];
  static int len = 0, pos = 0;
  if (pos == len) {
    pos = 0, len = fread(buf, 1, buf_size, stdin);
  }
  if (pos == len) {
    return -1;
  }
  return buf[pos++];
}
inline int readChar() {
  int c = getChar();
  while (c <= 32) {
    c = getChar();
  }
  return c;
}
template <class T>
inline T readInt() {
  int s = 1, c = readChar();
  T x = 0;
  if (c == '-') s = -1, c = getChar();
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar();
  return s == 1 ? x : -x;
}
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar(int x) {
  if (write_pos == buf_size)
    fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
  write_buf[write_pos++] = x;
}
template <class T>
inline void writeInt(T x, char end) {
  if (x < 0) writeChar('-'), x = -x;
  char s[24];
  int n = 0;
  while (x || !n) s[n++] = '0' + x % 10, x /= 10;
  while (n--) writeChar(s[n]);
  if (end) writeChar(end);
}
inline void writeWord(const char *s) {
  while (*s) writeChar(*s++);
}
struct Flusher {
  ~Flusher() {
    if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
  }
} flusher;
using namespace std;
const int MAXN = 200001;
int n;
vector<int> v[MAXN];
int ans = 0;
bool used[MAXN];
int lens[MAXN];
set<int> t[MAXN];
int cnt[MAXN];
int main() {
  n = readInt();
  for (int i = 0; i < n - 1; i++) {
    int a = readInt(), b = readInt();
    a--, b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  vector<int> g;
  for (int i = 0; i < n; i++) {
    cnt[i] = (int)(v[i]).size();
    if ((int)(v[i]).size() == 1) {
      g.push_back(i);
      lens[i] = 0;
    }
  }
  while (n > 2) {
    for (auto x : g) {
      used[x] = 1;
      cout << x << ' ' << lens[x] << endl;
    }
    vector<int> g1;
    for (auto x : g) {
      for (auto y : v[x]) {
        if (!used[y]) {
          cnt[y]--;
          g1.push_back(y);
          t[y].insert(lens[x] + 1);
        }
      }
    }
    n -= (int)(g).size();
    sort((g1).begin(), (g1).end());
    g1.resize(distance(g1.begin(), unique((g1).begin(), (g1).end())));
    g.clear();
    for (auto x : g1) {
      if ((int)(t[x]).size() >= 2 && cnt[x]) {
        writeInt(-1, '\n');
        return 0;
      }
      if (cnt[x] == 1) {
        lens[x] = *t[x].begin();
        g.push_back(x);
      }
      if (cnt[x] == 0) {
        g.push_back(x);
      }
    }
  }
  if ((int)(g).size() == 1) {
    if ((int)(t[g[0]]).size() > 2) {
      writeInt(-1, '\n');
      return 0;
    }
    ans = *t[g[0]].begin() + *t[g[0]].rbegin();
  } else {
    if ((int)(t[g[0]]).size() > 1) {
      writeInt(-1, '\n');
      return 0;
    }
    if ((int)(t[g[1]]).size() > 1) {
      writeInt(-1, '\n');
      return 0;
    }
    ans = *t[g[0]].begin() + *t[g[1]].begin() + 1;
  }
  writeInt(ans, '\n');
  return 0;
}
