import sys sys.setrecursionlimit(10 ** 6) N, K = list(map(int, input().split())) ab = [] for i in range(N-1): a, b = list(map(int, input().split())) ab.append([a-1, b-1]) if N < K: print(-1) exit() G = [] for i in range(N): G.append([False] * N) for a, b in ab: G[a][b] = True G[b][a] = True # for i in range(N): # print(G[i]) VISITED = [None] * N DEPTH = [None] * N def dfs(p, d): VISITED[p] = True DEPTH[p] = d # if all(VISITED): # return for i, b in enumerate(G[p]): if b and not VISITED[i]: dfs(i, d + 1) dfs(0, 0) # print(':', VISITED) # print(':', DEPTH) DEPTH.sort() ans = sum(DEPTH[:K]) print(ans)