from collections import deque n, k = list(map(int, input().split())) info = [list(map(int, input().split())) for i in range(n - 1)] tree = [[] for i in range(n)] for i in range(n - 1): a, b = info[i] a -= 1 b -= 1 tree[a].append(b) tree[b].append(a) if n < k: print(-1) exit() start = 0 visited = [-1] * n q = deque([0]) visited[0] = 0 while q: pos = q.popleft() for next_pos in tree[pos]: if visited[next_pos] >= 0: continue else: visited[next_pos] = visited[pos] + 1 q.append(next_pos) visited = sorted(visited) print(sum(visited[0:k]))