#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
struct Edge {
  int v, next;
} e[MAXN * 2];
int head[MAXN], NE = 0;
int n;
int dis[MAXN], flag = 0;
int ans1, ans2;
int root, cnt = -1, cut = -1;
int vis[MAXN];
void init() {
  NE = 0;
  memset(head, -1, sizeof(head));
}
void add_edge(int u, int v) {
  e[NE].v = v, e[NE].next = head[u];
  head[u] = NE++;
}
void dfs(int u, int fa) {
  if (flag != 0) return;
  dis[u] = 0;
  vis[u] = 1;
  int num = 0, ta, tb;
  for (int i = head[u]; i != -1; i = e[i].next) {
    int v = e[i].v;
    if (v == fa || v == cut) continue;
    dfs(v, u);
    if (flag != 0) return;
    if (num == 0) {
      num++;
      ta = dis[v] + 1;
    } else if (num == 1) {
      if (dis[v] + 1 != ta) {
        num++;
        tb = dis[v] + 1;
      }
    } else if (num == 2) {
      if (dis[v] + 1 != ta && dis[v] + 1 != tb) {
        flag = -1;
        return;
      }
    }
  }
  if (num == 0) {
    dis[u] = 0;
  } else if (num == 2) {
    root = fa;
    cut = u;
    cnt = 2;
    ans1 = ta;
    ans2 = tb;
    flag = 1;
    return;
  } else {
    dis[u] = ta;
  }
}
int main() {
  scanf("%d", &n);
  init();
  int tu, tv;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &tu, &tv);
    add_edge(tu, tv);
    add_edge(tv, tu);
  }
  memset(vis, 0, sizeof(vis));
  dfs(1, 1);
  if (flag == -1) {
    printf("-1\n");
  } else if (flag == 0) {
    while (dis[1] % 2 == 0) dis[1] /= 2;
    printf("%d\n", dis[1]);
  } else {
    if (root == cut) {
      int ret = ans1 + ans2;
      while (ret % 2 == 0) ret /= 2;
      printf("%d\n", ret);
      return 0;
    }
    flag = 0;
    dfs(root, root);
    if (flag != 0) {
      printf("-1\n");
    } else {
      if (dis[root] + 1 == ans1 || dis[root] + 1 == ans2) {
        int ret = ans1 + ans2;
        while (ret % 2 == 0) ret /= 2;
        printf("%d\n", ret);
      } else {
        printf("-1\n");
      }
    }
  }
  return 0;
}
