import queue from collections import namedtuple P = namedtuple("P", "i c") n, k = map(int, input().split()) path = {} cst = {} for i in range(1, n + 1): path[i] = set() cst[i] = -1 for _ in range(n - 1): a, b = map(int, input().split()) path[a] |= {b} path[b] |= {a} q = queue.Queue() q.put(P(1, 0)) while q.qsize() != 0: p = q.get() if cst[p.i] >= 0 and cst[p.i] < p.c: continue cst[p.i] = p.c for i in path[p.i]: q.put(P(i, p.c + 1)) lst = list() for v in cst.values(): lst.append(v) lst.sort() lst.reverse() ans = 0 for _ in range(k): if lst == list(): ans = -1 break ans += lst.pop() print(ans)