#ARC152F. [ARC152F] Attraction on Tree

[ARC152F] Attraction on Tree

Score : 10001000 points

Problem Statement

You are given a tree with NN vertices numbered 11 to NN. The ii-th edge connects two vertices aia_i and bib_i (1iN1)(1\leq i\leq N-1).

Initially, a piece is placed at vertex 11. You will perform the following operation exactly NN times.

  • Choose a vertex that is not occupied by the piece at that moment and is never chosen in the previous operations, and move the piece one vertex toward the chosen vertex.

A way to perform the operation NN times is called a good procedure if the piece ends up at vertex NN. Additionally, a good procedure is called an ideal procedure if the number of vertices visited by the piece at least once during the procedure (including vertices 11 and NN) is the minimum possible.

Find the number of vertices visited by the piece at least once during an ideal procedure. If there is no good procedure, print -1 instead.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1ai,biN1 \leq a_i,b_i \leq N
  • All values in the input are integers.
  • The given graph is a tree.

Input

The input is given from Standard Input in the following format:

NN

a1a_1 b1b_1

a2a_2 b2b_2

\vdots

aN1a_{N-1} bN1b_{N-1}

Output

Print the answer as an integer.

4
1 2
2 4
3 4
3

If you choose vertices 33, 11, 22, 44 in this order, the piece will go along the path 1122112244. This is an ideal procedure.

6
1 6
2 6
2 3
3 4
4 5
-1

There is no good procedure.

14
1 2
1 3
3 4
3 5
5 6
6 7
5 8
8 9
8 14
14 10
10 11
14 12
12 13
5