Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex *v*, and two disjoint (except for *v*) paths of equal length *a*<sub class="lower-index">0</sub> = *v*, *a*<sub class="lower-index">1</sub>, ..., *a*<sub class="lower-index">*k*</sub>, and *b*<sub class="lower-index">0</sub> = *v*, *b*<sub class="lower-index">1</sub>, ..., *b*<sub class="lower-index">*k*</sub>. Additionally, vertices *a*<sub class="lower-index">1</sub>, ..., *a*<sub class="lower-index">*k*</sub>, *b*<sub class="lower-index">1</sub>, ..., *b*<sub class="lower-index">*k*</sub> must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices *b*<sub class="lower-index">1</sub>, ..., *b*<sub class="lower-index">*k*</sub> can be effectively erased:

Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.
The first line of input contains the number of vertices *n* (2 ≤ *n* ≤ 2·10<sup class="upper-index">5</sup>).

Next *n* - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers *u* and *v* (1 ≤ *u*, *v* ≤ *n*, *u* ≠ *v*) — indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.
In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.

It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
6
1 2
2 3
2 4
4 5
1 6
3
7
1 2
1 3
3 4
1 5
5 6
6 7
-1
2
1 2
1
3
3 1
1 2
1
10
5 10
7 8
8 3
2 6
3 2
9 7
4 5
10 1
6 4
9
11
11 9
6 7
7 1
8 11
5 6
3 5
9 3
10 8
2 4
4 10
5
10
4 2
7 4
2 6
2 5
4 8
10 3
2 9
9 1
5 10
-1
11
8 9
2 7
1 11
3 2
9 1
8 5
8 6
5 4
4 10
8 3
1
12
12 6
6 7
8 11
4 8
10 4
12 3
2 10
6 2
12 9
4 1
9 5
-1
4
4 1
4 3
4 2
1
5
1 5
2 3
2 4
1 2
3
6
1 6
3 1
6 4
5 3
2 5
5
7
5 6
5 7
5 1
7 4
6 3
3 2
-1
8
6 1
4 7
4 8
8 5
7 6
4 3
4 2
-1
3
1 3
3 2
1
5
5 4
4 3
3 1
5 2
1
9
1 2
1 3
1 4
1 5
1 6
6 7
6 8
8 9
3
from collections import deque
import sys
import io
import os




MOD = 998244353  # 1000000007   INV2 = (MOD + 1) >> 1 # pow(2, MOD - 2, MOD)
inf = (1 << 60) - 1


def solve_topsort():
    n = read_int()
    
    g = [[] for _ in range(n)]
    ind = [0] * n
    for _ in range(n - 1):
        u, v = read_int_tuple()
        u -= 1; v -= 1
        g[u].append(v)
        g[v].append(u)
        ind[u] += 1
        ind[v] += 1
    
    if n == 2:
        print(1)
        return
        
    q = deque([u for u in range(n) if ind[u] == 1])
    
    book = [set() for _ in range(n)]
    for u in q:
        book[u].add(0)
    c2 = 0
    while q:
        u = q.popleft()
        ind[u] = 0
        if len(book[u]) > 1:
            c2 += 1
        for v in g[u]:
            if ind[v] == 0: continue
            for p in book[u]:
                book[v].add(p + 1)
            ind[v] -= 1
            if ind[v] == 1:
                q.append(v)
    
        if c2 > 1:
            print(-1)
            return
    
    if len(book[u]) > 2:
        print(-1)
        return
    res = sum(book[u])
    while res & 1 == 0:
        res >>= 1
    print(res)
    
def solve():
    n = read_int()
    g = [[] for _ in range(n)]
    for _ in range(n - 1):
        u, v = read_int_tuple()
        u -= 1; v -= 1
        g[u].append(v)
        g[v].append(u)
    
    if n == 2:
        print(1)
        return

    # step1
    root = 0
    parent = [-1] * n  # 记录父亲结点
    order = [root]  # 记录dfs序，深度单调增加
    stack = [root]
    while stack:
        from_node = stack.pop()
        for to_node in g[from_node]:
            if to_node == parent[from_node]:
                continue
            parent[to_node] = from_node
            order.append(to_node)
            stack.append(to_node)
    
    # step2
    e = lambda _: (0, True)
    
    def merge(a, b):
        if a[0] == 0:
            return b
        if b[0] == 0:
            return a

        return (a[0], a[0] == b[0] and a[1] and b[1])
        
    def op(cur, u, v):
        return (cur[0] + 1, cur[1])
    
    dp1 = list(map(e, range(n)))
    dp2 = list(map(e, range(n)))
    
    for from_node in order[::-1]:
        t = e(from_node)
        for to_node in g[from_node]:
            if parent[from_node] == to_node:
                continue
            dp2[to_node] = t
            t = merge(t, op(dp1[to_node], from_node, to_node))
        t = e(from_node)
        for to_node in g[from_node][::-1]:
            if parent[from_node] == to_node:
                continue
            dp2[to_node] = merge(t, dp2[to_node])
            t = merge(t, op(dp1[to_node], from_node, to_node))
        dp1[from_node] = t

    # step3
    for new_root in order[1:]:  # 把最终结果放入dp1，res[u] = merge(dp1[u], dp2[u])
        par = parent[new_root]
        dp2[new_root] = op(merge(dp2[new_root], dp2[par]), new_root, par)
        dp1[new_root] = merge(dp1[new_root], dp2[new_root])
    
    res = inf
    for r, t in dp1:
        if t:
            while r & 1 == 0:
                r >>= 1
            if res > r:
                res = r
        
    print(-1 if res == inf else res)

def main():
    # region local test
    # if 'AW' in os.environ.get('COMPUTERNAME', ''):
    #     test_no = 1
    #     f = open(os.path.dirname(__file__) + f'\\in{test_no}.txt', 'r')

    #     global input
    #     input = lambda: f.readline().rstrip("\r\n")
    # endregion
    
    T = 1#read_int()
    for t in range(T):
        solve()
        # print('Yes' if solve() else 'No')


# region IO
BUFSIZE = 8192


class FastIO(io.IOBase):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.buffer = io.BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(io.IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


input = lambda: sys.stdin.readline().rstrip('\r\n')


def read_int_list():
    return list(map(int, input().split()))


def read_int_tuple():
    return map(int, input().split())


def read_int():
    return int(input())

read_str = input


# endregion


if __name__ == "__main__":
    main()