n, k = map(int, input().split()) if n < k: print(-1) exit(0) g = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) g[a - 1].append(b - 1) g[b - 1].append(a - 1) s = [0] d = [-1] * n d[0] = 0 while s: p = s.pop() for node in g[p]: if d[node] == -1: d[node] = d[p] + 1 s.append(node) d.sort() print(sum(d[:k]))