Under construction

Still being built. Things may change

Garden Pruning

Time limit2sMemory limit128 MB

Summary
Find the minimum number of edge cuts needed to prune a tree down to exactly m vertices while keeping it connected.
Level

Medium6 of 10

Topics
Dynamic programming, Tree, DFS
Solved
No attempts yet

Problem

While cleaning a garden, Sangwook found a tree that had grown into a messy shape. It is time to prune it.

The garden tree is represented as a connected graph with n vertices and n - 1 edges. Each vertex is a leaf of the garden tree, and each edge is a branch.

Sangwook wants to prune the tree so that exactly m vertices remain. One pruning operation cuts one edge in the currently kept tree. When the cut splits the graph into two connected components, he keeps one component and discards the other.

Given the shape of the tree, find the minimum number of pruning operations needed to finish the job.

Input

The first line contains n and m (1 <= n <= 150, 1 <= m <= n).

Each of the next n - 1 lines contains two vertex numbers describing one branch of the tree. The two numbers mean that there is an edge connecting those vertices. Vertex numbers are integers from 1 to n.

Output

Print the minimum number of pruning operations. If it is impossible, print -1.

Hint

For the public test, cutting edges 1-4 and 1-5 leaves a tree with the desired size.

Examples1

  1. Example 1

    Input
    11 6
    1 2
    1 3
    1 4
    1 5
    2 6
    2 7
    2 8
    4 9
    4 10
    4 11
    
    Expected output
    2