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_0 = v, a_1, ..., a_{k}, and b_0 = v, b_1, ..., b_{k}. Additionally, vertices a_1, ..., a_{k}, b_1, ..., b_{k} 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_1, ..., b_{k} can be effectively erased: [Image] 

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.


-----Input-----

The first line of input contains the number of vertices n (2 ≤ n ≤ 2·10^5).

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.


-----Output-----

If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.


-----Examples-----
Input
6
1 2
2 3
2 4
4 5
1 6

Output
3

Input
7
1 2
1 3
3 4
1 5
5 6
6 7

Output
-1



-----Note-----

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.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\ndef LI(): return list(map(int, input().split()))\ndef II(): return int(input())\ndef LS(): return input().split()\ndef S(): return input()\n\n\ndef main():\n    n = II()\n    d = collections.defaultdict(set)\n    for _ in range(n-1):\n        a,b = LI()\n        d[a].add(b)\n        d[b].add(a)\n\n    memo = {}\n    def path(t,s):\n        ps = set()\n        dt = list(d[t])\n        for k in dt:\n            if k not in memo:\n                continue\n            if memo[k] in ps:\n                d[k] -= set([t])\n                d[t] -= set([k])\n            ps.add(memo[k])\n\n        if s == -1 and len(ps) == 2:\n            memo[t] = sum(ps) + 2\n            return memo[t]\n\n        if len(ps) > 1:\n            return -t\n\n        if len(ps) == 0:\n            memo[t] = 0\n            return 0\n\n        memo[t] = list(ps)[0] + 1\n        return memo[t]\n\n    def _path(tt,ss):\n        q = [(tt,ss)]\n        tq = []\n        qi = 0\n        while len(q) > qi:\n            t,s = q[qi]\n            for k in d[t]:\n                if k == s:\n                    continue\n                q.append((k,t))\n            qi += 1\n        for t,s in q[::-1]:\n            r = path(t,s)\n            if r < 0:\n                return r\n        return memo[tt]\n\n    def _path2(tt,ss):\n        q = [(tt,ss)]\n        tq = []\n        qi = 0\n        while len(q) > qi:\n            t,s = q[qi]\n            for k in d[t]:\n                if k == s or k in memo:\n                    continue\n                q.append((k,t))\n            qi += 1\n        for t,s in q[::-1]:\n            r = path(t,s)\n            if r < 0:\n                return r\n        return memo[tt]\n\n    t = _path(1,-1)\n    if t < 0:\n        t = _path2(-t,-1)\n\n    if t > 0:\n        while t%2 == 0:\n            t//=2\n        return t\n\n    return -1\n\nprint(main())\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14705