import sys input = sys.stdin.readline from collections import deque def bfs(G, s): Q = deque([s]) N = len(G) dist = [-1] * N par = [-1] * N dist[s] = 0 while Q: u = Q.popleft() for v in G[u]: if dist[v] != -1: continue dist[v] = dist[u] + 1 par[v] = u Q.append(v) return dist N, K = map(int, input().split()) G = [[] for i in range(N)] for i in range(N - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 G[a].append(b) G[b].append(a) if K >= N + 1: print(-1) exit() print(sum(sorted(bfs(G, 0))[:K]))