You are given a tree of $N$ vertices, numbered $1, 2, ..., N$. You want to determine a positive integer value $M$ and draw this tree on a region $R = \{(x,y) | 0 \leq x \leq M-1, 0 \leq y \leq 1\}$ on a two-dimensional coordinate plane.
In this drawing, the vertices of the tree should be placed at grid points within $R$, and the edges of the tree should be drawn as straight line segments. Furthermore, these line segments representing different edges of the tree should not share any points other than their endpoints.
More formally, you want to construct a mapping $p$ from the vertex set of tree $T$ to the set of grid points $\{(x,y) | x \in \{0, 1, ..., M-1\}, y \in \{0, 1\}\}$ such that the following properties are satisfied:
Your task is to determine if such a drawing is possible by choosing an appropriate $M$, and if possible, find the minimum value of $M$.
The input consists of a single test case of the following format.
$N$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_{N-1}$ $v_{N-1}$
The first line consists of an integer $N$, which is between $1$ and $50,000$, inclusive.
Each of the following $N-1$ lines contains two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq N$). $u_i$ and $v_i$ denote the endpoints of the $i$-th edge of $T$.
It is guaranteed that the given graph is a tree.
Output a single integer — the minimum possible value of $M$ to achieve the goal. If it is impossible to do so, output -1 as the answer.
6 1 2 1 3 1 4 1 5 1 6
3
21 1 2 1 3 1 4 1 5 6 7 6 8 6 9 6 10 11 12 11 13 11 14 11 15 16 17 16 18 16 19 16 20 5 21 10 21 15 21 20 21
-1
18 1 2 2 3 2 4 2 5 1 6 6 7 6 8 6 9 1 12 10 11 11 12 12 13 13 14 1 16 15 16 16 17 17 18
11
21 20 10 7 2 7 17 18 5 3 1 15 17 11 7 14 18 11 21 6 2 8 19 17 14 4 18 16 17 9 10 19 17 18 12 15 3 13 15 16 10
11