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

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.TreeSet;

public class E2 {

  private void solve(Scanner in, PrintWriter out) {
    int N = in.nextInt();
    ArrayList<Integer>[] tree = new ArrayList[N];

    //branches[v] := vにぶら下がっている枝の数
    TreeSet<Integer>[] branches = new TreeSet[N];

    //done[v] := vより下の枝で処理が終わった物の数
    int[] done = new int[N];

    boolean[] visited = new boolean[N];
    for (int i = 0; i < N; i++) {
      tree[i] = new ArrayList<>();
      branches[i] = new TreeSet<>();
    }

    for (int i = 0; i < N - 1; i++) {
      int u = in.nextInt() - 1;
      int v = in.nextInt() - 1;
      tree[v].add(u);
      tree[u].add(v);
    }

    ArrayDeque<Integer> deque = new ArrayDeque<>();

    //葉をキューに詰める
    for (int i = 0; i < N; i++) {
      if (tree[i].size() == 1) {
        deque.add(i);
      }
    }

    while (!deque.isEmpty()) {
      int v = deque.poll();
      visited[v] = true;

      //vに3種類以上の長さの枝がぶら下がっている場合どうやっても不可能なので終了する
      if (branches[v].size() >= 3) {
        out.println(-1);
        return;
      }

      //v以外の枝のマージが全て終わったとき、ツリーは直線になっているはずである
      if (done[v] == tree[v].size()) {
        int ans = 0;
        for (int branch : branches[v]) {
          ans += branch;
        }

        //半分に折れる限り折る
        while (ans % 2 == 0) {
          ans /= 2;
        }
        out.println(ans);
        return;
      }

      //自分の下にある枝の長さの種類が2のとき、vは中心になっているはずであるが、
      // その場合は既に処理が終わっているはずなので、vは中心でない
      if (branches[v].size() == 2) {
        out.println(-1);
        return;
      }

      //vにぶら下がっている枝の長さ
      int length = branches[v].isEmpty() ? 0 : branches[v].first();

      for (int parent : tree[v]) {
        if (visited[parent]) {
          continue;
        }

        done[parent]++;
        branches[parent].add(length + 1);

        //parentより下の枝のマージが終わったらキューに詰める
        if (done[parent] + 1 == tree[parent].size()) {
          deque.add(parent);
        }
      }
    }
    throw new IllegalStateException();
  }


  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new E2().solve(in, out);
    out.close();
  }

  private static class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int bufferLength = 0;

    private boolean hasNextByte() {
      if (ptr < bufferLength) {
        return true;
      } else {
        ptr = 0;
        try {
          bufferLength = in.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (bufferLength <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte()) {
        return buffer[ptr++];
      } else {
        return -1;
      }
    }

    private static boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
        ptr++;
      }
    }

    boolean hasNext() {
      skipUnprintable();
      return hasNextByte();
    }

    public String next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    long nextLong() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    double[] nextDoubleArray(int n) {
      double[] array = new double[n];
      for (int i = 0; i < n; i++) {
        array[i] = nextDouble();
      }
      return array;
    }

    double[][] nextDoubleMap(int n, int m) {
      double[][] map = new double[n][];
      for (int i = 0; i < n; i++) {
        map[i] = nextDoubleArray(m);
      }
      return map;
    }

    public int nextInt() {
      return (int) nextLong();
    }

    public int[] nextIntArray(int n) {
      int[] array = new int[n];
      for (int i = 0; i < n; i++) {
        array[i] = nextInt();
      }
      return array;
    }

    public long[] nextLongArray(int n) {
      long[] array = new long[n];
      for (int i = 0; i < n; i++) {
        array[i] = nextLong();
      }
      return array;
    }

    public String[] nextStringArray(int n) {
      String[] array = new String[n];
      for (int i = 0; i < n; i++) {
        array[i] = next();
      }
      return array;
    }

    public char[][] nextCharMap(int n) {
      char[][] array = new char[n][];
      for (int i = 0; i < n; i++) {
        array[i] = next().toCharArray();
      }
      return array;
    }

    public int[][] nextIntMap(int n, int m) {
      int[][] map = new int[n][];
      for (int i = 0; i < n; i++) {
        map[i] = nextIntArray(m);
      }
      return map;
    }
  }
}
