from collections import deque n, k = map(int, input().split()) if n < k: print(-1) exit() edges = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) edges[a - 1].append(b - 1) edges[b - 1].append(a - 1) queue = deque() queue.append(0) queue.append(0) ans = 0 check = [False for _ in range(n)] check[0] = True while queue: if k == 0: break pos = queue.popleft() cnt = queue.popleft() ans += cnt k -= 1 for n_pos in edges[pos]: if check[n_pos]: continue check[n_pos] = True queue.append(n_pos) queue.append(cnt + 1) print(ans)