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;
const long long INF = 1 << 28;
const long long LINF = 1ll << 61;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
inline char mygetchar() {
  register char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
int a[1600111], tag[1600111], ia[1600111];
void update(int p) {
  if (a[p << 1] == 23333333 || a[p << 1 | 1] == 23333333 ||
      a[p << 1] != a[p << 1 | 1])
    a[p] = 23333333;
  else
    a[p] = a[p << 1];
}
void pushdown(int p) {
  if (tag[p]) {
    a[p << 1] += tag[p];
    a[p << 1 | 1] += tag[p];
    tag[p << 1] += tag[p];
    tag[p << 1 | 1] += tag[p];
    tag[p] = 0;
  }
}
void modify(int x, int y, int l, int r, int dlt, int p = 1) {
  if (x <= l && r <= y) {
    a[p] += dlt;
    tag[p] += dlt;
    return;
  }
  pushdown(p);
  int m = l + r >> 1;
  if (x <= m) modify(x, y, l, m, dlt, p << 1);
  if (m < y) modify(x, y, m + 1, r, dlt, p << 1 | 1);
  update(p);
}
void build(int l, int r, int p = 1) {
  if (l == r) {
    a[p] = ia[l];
    return;
  }
  int m = l + r >> 1;
  build(l, m, p << 1);
  build(m + 1, r, p << 1 | 1);
  update(p);
}
int query(int x, int y, int l, int r, int p = 1) {
  if (x <= l && r <= y) return a[p];
  pushdown(p);
  int m = l + r >> 1;
  if (x <= m && m < y) {
    int tl = query(x, y, l, m, p << 1), tr = query(x, y, m + 1, r, p << 1 | 1);
    if (tl == 23333333 || tr == 23333333 || tl != tr)
      return 23333333;
    else
      return tl;
  } else if (x <= m)
    return query(x, y, l, m, p << 1);
  else
    return query(x, y, m + 1, r, p << 1 | 1);
}
int n, tot = 1, head[800111], nxt[800111], to[800111], dfn[800111], dfnt = 1,
       dfnr[800111], deg[800111];
void idfs(int x, int pre = -1, int l = 1) {
  dfn[x] = dfnt;
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] == pre) continue;
    idfs(to[i], x, l + 1);
  }
  if (deg[x] == 1) {
    ia[dfnt] = l;
    dfnt++;
  }
  dfnr[x] = dfnt;
}
int ans = 23333333;
void dfs(int x, int pre = -1, int l = 1) {
  if (deg[x] == 1) {
    int t = -1, tmp;
    if (dfn[x] > 1) {
      tmp = query(1, dfn[x] - 1, 1, dfnt - 1);
      if (t == -1) t = tmp;
      if (t == 23333333 || tmp == 23333333 || t != tmp) t = 23333333;
    }
    if (dfn[x] < dfnt - 1) {
      tmp = query(dfn[x] + 1, dfnt - 1, 1, dfnt - 1);
      if (t == -1) t = tmp;
      if (t == 23333333 || tmp == 23333333 || t != tmp) t = 23333333;
    }
    if (t != 23333333) {
      ans = min(ans, t + l - 2);
    }
  } else {
    int t = a[1];
    if (t != 23333333) {
      ans = min(ans, (t + l - 2) * 2);
    }
  }
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] == pre) continue;
    modify(dfn[to[i]], dfnr[to[i]] - 1, 1, dfnt - 1, -2);
    dfs(to[i], x, l + 1);
    modify(dfn[to[i]], dfnr[to[i]] - 1, 1, dfnt - 1, 2);
  }
}
void add(int x, int y) {
  nxt[++tot] = head[x];
  head[x] = tot;
  to[tot] = y;
  nxt[++tot] = head[y];
  head[y] = tot;
  to[tot] = x;
  deg[x]++;
  deg[y]++;
}
int main() {
  n = getnum();
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    x = getnum(), y = getnum();
    add(x, n + i);
    add(n + i, y);
  }
  int root;
  for (int i = 1; i <= n; i++)
    if (deg[i] > 1) {
      root = i;
      break;
    }
  idfs(root);
  build(1, dfnt - 1);
  dfs(root);
  if (ans == 23333333)
    puts("-1");
  else
    cout << ans / 2 << endl;
  return 0;
}
