#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
  x = 0;
  char c;
  int f = 1;
  while (c = getchar(), c < 48)
    if (c == '-') f = -1;
  do x = x * 10 + (c & 15);
  while (c = getchar(), c > 47);
  x *= f;
}
template <class T>
void prin(T x) {
  if (!x) return;
  prin(x / 10);
  putchar(x % 10 ^ 48);
}
template <class T>
void pf(T x) {
  if (x < 0)
    putchar('-'), x = -x;
  else if (!x)
    putchar('0');
  prin(x);
}
template <class T>
void ptn(T x) {
  pf(x);
  putchar('\n');
}
template <class T>
void ptk(T x) {
  pf(x);
  putchar(' ');
}
template <class T>
void Min(T &A, T B) {
  if (A > B) A = B;
}
template <class T>
void Max(T &A, T B) {
  if (A < B) A = B;
}
const int N = (int)4e5;
pair<int, int> G[N << 1];
int head[N], tot, n;
int par[N], dep[N], id, mx;
void dfs(int x) {
  if (dep[x] > mx) {
    mx = dep[x];
    id = x;
  }
  for (int i = head[x]; i; i = G[i].second) {
    int y = G[i].first;
    if (y == par[x]) continue;
    par[y] = x;
    dep[y] = dep[x] + 1;
    dfs(y);
  }
}
int que[N], fir[N], sec[N];
bool Lcan[N], Rcan[N];
bool mark[N];
struct ss {
  int fir, sec, thr;
};
ss getans(int x) {
  set<int> a;
  a.clear();
  for (int i = head[x]; i; i = G[i].second) {
    int y = G[i].first;
    if (y == par[x] || mark[y]) continue;
    par[y] = x;
    ss tmp = getans(y);
    if (tmp.thr == 0) return (ss){0, 0, 0};
    if (tmp.sec) return (ss){0, 0, 0};
    a.insert(tmp.fir);
  }
  if (a.size() > 2) return (ss){0, 0, 0};
  if (!a.size()) return (ss){1, 0, 1};
  if (a.size() == 1) return (ss){(*a.begin()) + 1, 0, 1};
  ss b;
  b.fir = (*a.begin()) + 1;
  a.erase(b.fir - 1);
  b.sec = (*a.begin()) + 1;
  b.thr = 1;
  return b;
}
int main() {
  rd(n);
  for (int x, y, i = 1; i < n; ++i) {
    rd(x);
    rd(y);
    G[++tot] = pair<int, int>(y, head[x]);
    head[x] = tot++;
    G[++tot] = pair<int, int>(x, head[y]);
    head[y] = tot++;
  }
  mx = -1, par[id = 1] = 0;
  dfs(1);
  mx = -1;
  dep[id] = 0;
  par[id] = 0;
  dfs(id);
  int cnt = 0;
  while (id) {
    que[++cnt] = id;
    mark[id] = 1;
    id = par[id];
  }
  Lcan[1] = Lcan[2] = true;
  Rcan[cnt] = 1;
  if (cnt > 0) Rcan[cnt - 1] = true;
  for (int i = (2), _t = (cnt); i < _t; ++i) {
    par[que[i]] = 0;
    ss tmp = getans(que[i]);
    if (tmp.thr == 0) {
      puts("-1");
      return 0;
    }
    tmp.fir--;
    if (!Lcan[i] || tmp.fir != i - 1) {
      fir[i] = tmp.fir;
    }
    if (Lcan[i] && tmp.sec) {
      tmp.sec--;
      if (tmp.sec != i - 1) {
        if (fir[i])
          sec[i] = tmp.sec;
        else
          fir[i] = tmp.sec;
      }
    } else if (!Lcan[i] && tmp.sec)
      sec[i] = tmp.sec - 1;
    if (fir[i] || sec[i] || !Lcan[i])
      Lcan[i + 1] = false;
    else
      Lcan[i + 1] = true;
  }
  for (int i = (cnt)-1, _s = (2); i >= _s; --i) {
    if (Rcan[i]) {
      if (fir[i]) {
        if (fir[i] == cnt - i) fir[i] = 0;
      }
      if (sec[i]) {
        if (sec[i] == cnt - i) sec[i] = 0;
      }
    }
    if (fir[i] || sec[i] || !Rcan[i])
      Rcan[i - 1] = false;
    else
      Rcan[i - 1] = true;
  }
  int c = 0;
  for (int i = (2), _t = (cnt); i < _t; ++i)
    if (fir[i] || sec[i]) c++;
  if (c > 1) {
    puts("-1");
    return 0;
  }
  for (int i = (2), _t = (cnt); i < _t; ++i)
    if (fir[i] || sec[i]) {
      if (fir[i] && sec[i]) {
        puts("-1");
        return 0;
      }
      if (i - 1 != cnt - i) {
        puts("-1");
        return 0;
      }
      int lg = fir[i] | sec[i];
      mx >>= 1;
      mx += lg;
    }
  while ((!(mx & 1)) && mx) mx >>= 1;
  ptn(mx);
  return 0;
}
