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 int INF = 1791791791;
const long long INFLL = 1791791791791791791ll;
template <int input_buf_size, int output_buf_size>
class FastIO {
  char cbuf[input_buf_size + 1];
  int icur = 0;
  inline bool go_to_next_token() {
    while (cbuf[icur] == ' ' || cbuf[icur] == '\n') icur++;
    while (cbuf[icur] == 0) {
      icur = 0;
      if (fgets(cbuf, sizeof(cbuf), stdin) != cbuf) return false;
      while (cbuf[icur] == ' ' || cbuf[icur] == '\n') icur++;
    }
    return true;
  }

 public:
  string readString() {
    assert(go_to_next_token());
    string ans;
    while (cbuf[icur] != ' ' && cbuf[icur] != '\n' && cbuf[icur] != 0)
      ans.push_back(cbuf[icur++]);
    ans.shrink_to_fit();
    return ans;
  }
  template <class int_type>
  int_type readInt() {
    assert(go_to_next_token());
    int_type x = 0;
    bool m = cbuf[icur] == '-';
    if (m) icur++;
    while ('0' <= cbuf[icur] && cbuf[icur] <= '9') {
      x *= 10;
      x += (cbuf[icur] - '0');
      icur++;
    }
    if (m) x = -x;
    return x;
  }
  bool seekEof() { return !go_to_next_token(); }

 private:
  char obuf[output_buf_size + 1];
  int ocur = 0;
  inline void write_string(const char *str, size_t sz = 0) {
    if (sz == 0) sz = strlen(str);
    if (ocur + sz > output_buf_size) {
      fputs(obuf, stdout);
      fputs(str, stdout);
      ocur = 0;
      obuf[0] = 0;
      return;
    }
    strcpy(obuf + ocur, str);
    ocur += sz;
    obuf[ocur] = 0;
  }

 public:
  template <class int_type>
  void writeInt(int_type x, bool sp = true) {
    char buf[20];
    int c = 0;
    if (x < 0) {
      buf[c++] = '-';
      x = -x;
    }
    int s = c;
    if (x == 0) {
      buf[c++] = '0';
    }
    while (x > 0) {
      buf[c++] = (x % 10) + '0';
      x /= 10;
    }
    for (int i = 0; 2 * i < c - s; i++) {
      swap(buf[s + i], buf[c - 1 - i]);
    }
    buf[c] = 0;
    write_string(buf, c);
    if (sp) write_string(" ", 1);
  }
  void writeString(string s, bool space = true) {
    write_string(s.c_str(), s.size());
    if (space) write_string(" ", 1);
  }
  void writeEndl() { write_string("\n", 1); }
  void flush() {
    fputs(obuf, stdout);
    ocur = 0;
    obuf[0] = 0;
  }

 private:
  bool lflush;

 public:
  FastIO(bool local_flush) {
    obuf[0] = 0;
    lflush = local_flush;
  }
  ~FastIO() { fputs(obuf, stdout); }
};
FastIO<10000000, 10000000> IO(true);
const int maxn = (int)2e5 + 179;
vector<int> tree[maxn];
vector<int> hg;
void hdfs(int v, int par) {
  hg[v] = 0;
  for (int u : tree[v]) {
    if (u != par) {
      hdfs(u, v);
      if (hg[u] == -1) hg[v] = -1;
    }
  }
  if (hg[v] != -1) {
    int val = -1;
    for (int u : tree[v]) {
      if (u != par) {
        if (val == -1)
          val = hg[u];
        else if (val != hg[u])
          hg[v] = -1;
      }
    }
    if (hg[v] != -1) hg[v] = val + 1;
  }
}
map<pair<int, int>, int> hg_of_all;
void dfs(int v, int par, int uphg) {
  if (par != -1) {
    hg_of_all[make_pair(v, par)] = uphg;
  }
  for (int u : tree[v]) {
    if (u != par) {
      hg_of_all[make_pair(v, u)] = (hg[u] == -1 ? -1 : hg[u] + 1);
    }
  }
  if (uphg == -1 && par != -1) {
    for (int u : tree[v]) {
      if (u != par) dfs(u, v, -1);
    }
    return;
  }
  int up;
  if (par == -1)
    up = 0;
  else
    up = uphg;
  int cnt = 0;
  for (int u : tree[v]) {
    if (u != par) {
      cnt += (hg_of_all[make_pair(v, u)] != up);
    }
  }
  if (cnt >= 2) {
    for (int u : tree[v]) {
      if (u != par) {
        dfs(u, v, -1);
      }
    }
  } else if (cnt == 1) {
    for (int u : tree[v]) {
      if (u != par) {
        dfs(u, v, (hg_of_all[make_pair(v, u)] != up ? up + 1 : -1));
      }
    }
  } else {
    for (int u : tree[v]) {
      if (u != par) {
        dfs(u, v, up + 1);
      }
    }
  }
}
int main() {
  int n = IO.readInt<int>();
  for (int i = 0; i < ((int)(n - 1)); ++i) {
    int u = IO.readInt<int>() - 1;
    int v = IO.readInt<int>() - 1;
    tree[u].push_back(v);
    tree[v].push_back(u);
  }
  int root = -1;
  for (int i = 0; i < ((int)(n)); ++i)
    if (tree[i].size() == 1) root = i;
  hg.resize(n);
  hdfs(root, -1);
  dfs(root, -1, -1);
  int ans = INF;
  for (int i = 0; i < ((int)(n)); ++i) {
    vector<int> hs;
    for (int u : tree[i]) hs.push_back(hg_of_all[make_pair(i, u)]);
    sort((hs).begin(), (hs).end());
    if (hs[0] == -1) continue;
    hs.resize(distance(hs.begin(), unique((hs).begin(), (hs).end())));
    if (hs.size() == 2)
      ans = min(ans, hs[0] + hs[1]);
    else if (hs.size() == 1)
      ans = min(ans, hs[0]);
  }
  if (ans == INF) ans = -1;
  IO.writeInt(ans);
  IO.writeEndl();
  return 0;
}
