import sys input = sys.stdin.readline N,K=map(int,input().split()) if K>N: print(-1) sys.exit() E=[[] for i in range(N+1)] ANS=[-1]*(N+1) for i in range(N-1): x,y=map(int,input().split()) E[x].append(y) E[y].append(x) from collections import deque Q=deque() Q.append(1) ANS[1]=0 while Q: x=Q.popleft() for to in E[x]: if ANS[to]==-1: ANS[to]=ANS[x]+1 Q.append(to) ANS.sort() print(sum(ANS[1:1+K]))