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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.PriorityQueue;
import java.util.Collection;
import java.util.Set;
import java.util.AbstractQueue;
import java.io.IOException;
import java.util.HashSet;
import java.util.AbstractCollection;
import java.util.stream.Stream;
import java.util.Optional;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            ETreeFolding solver = new ETreeFolding();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class ETreeFolding {
        public void solve(int testNumber, FastInput in, PrintWriter out) {
            int n = in.readInt();
            Node[] nodes = new Node[n];
            for (int i = 0; i < n; i++) {
                nodes[i] = new Node();
                nodes[i].id = i;
            }
            for (int i = 0; i < n - 1; i++) {
                Node a = nodes[in.readInt() - 1];
                Node b = nodes[in.readInt() - 1];
                a.adj.add(b);
                b.adj.add(a);
            }

            PriorityQueue<Node> pq = new PriorityQueue<>((a, b) -> Integer.compare(a.length, b.length));
            for (Node node : nodes) {
                if (node.adj.size() == 1) {
                    pq.add(node);
                }
            }
            while (!pq.isEmpty()) {
                Node head = pq.remove();
                int len = head.length + 1;
                if (head.adj.isEmpty()) {
                    int ans = head.set.stream().mapToInt(Integer::intValue).sum();
                    while (ans % 2 == 0) {
                        ans /= 2;
                    }
                    out.print(ans);
                    return;
                }
                Node other = head.adj.stream().findAny().get();
                other.adj.remove(head);
                other.set.add(len);
                if (other.adj.size() + other.set.size() <= 2) {
                    other.length = other.set.stream().findAny().get();
                    pq.add(other);
                }
            }

            out.print(-1);

        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class Node {
        Set<Node> adj = new HashSet<>();
        Set<Integer> set = new HashSet<>();
        int length;
        int id;

        public String toString() {
            return "" + (id + 1);
        }

    }
}

