from sys import setrecursionlimit setrecursionlimit(10**5) n,k=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(n-1): a,b=map(int,input().split()) g[a-1].append(b-1) g[b-1].append(a-1) d=[-1]*n d[0]=1 def dfs(now,pre): for to in g[now]: if to==pre: continue d[to]=d[now]+1 dfs(to,now) dfs(0,-1) if max(d)>=k: print(k-1) else: print(-1)