Patrol

Time limit1sMemory limit64 MB

Problem

There are $N$ villages numbered $1$ through $N$, joined by $N-1$ roads that connect all of them. Each road links exactly two villages, and from any village you can reach every other village using only these roads (so the roads form a tree). Each road has length $1$.

To keep everyone safe, a patrol must travel along every road every day. The police station is in village $1$, so each day the patrol starts at village $1$ and must finally return to village $1$. Note that to finish a day's duty the patrol has to travel along each road exactly twice, so on a tree the total distance is $2(N-1)$; for example, on a certain tree of $8$ villages this distance is $14$.

To reduce the total distance the patrol travels, $K$ new shortcuts will be built between the villages. Each shortcut is a new road of length $1$ connecting two villages. Two shortcuts may start at the same village, and a shortcut may even be a loop, that is, connect a village to itself. Because the budget is limited, $K$ is $1$ or $2$. So that no money is wasted, the patrol must travel along each shortcut exactly once per day.

On the tree of $8$ villages above, building one well-chosen shortcut lowers the patrol's total distance to $11$, and building two shortcuts can lower it to $10$. A poorly chosen pair of shortcuts, however, can even make the total larger than $14$ (for instance $15$), precisely because the patrol is required to travel each shortcut exactly once.

Given the roads and the number $K$ of shortcuts to build, decide where to build the shortcuts so that the total distance the patrol travels each day is as small as possible, and output that minimum distance.

Input

The first line contains two integers $N$ ($3 \le N \le 100000$) and $K$ ($1 \le K \le 2$).

Each of the next $N-1$ lines contains two integers $A$ and $B$ ($1 \le A, B \le N$), meaning there is a road connecting villages $A$ and $B$.

Output

Output a single integer: the minimum possible total distance the patrol must travel each day after building the $K$ shortcuts optimally.