from collections import deque n,k = map(int,input().split()) ab = [[] for i in range(n)] for i in range(n-1): a,b = map(int,input().split()) a -= 1 b -= 1 ab[a].append(b) ab[b].append(a) d = deque() d.append([0,0]) chk = [0]*(n) chk[0] = 1 f = False cnt = 0 while f == False and len(d) > 0: tmp,num = d.popleft() for i in ab[tmp]: if chk[i] == 0: chk[i] = 1 d.append([i,num+1]) k -= 1 cnt += 1 if k == 1: f = True break #print(k) if f == True: print(cnt) else: print(-1)