import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from collections import deque n, k = map(int, readline().split()) graph = [[] for _ in range(n)] for i in range(n - 1): a, b = map(int, readline().split()) graph[a - 1].append(b - 1) def dfs(s): global k cnt = 0 check = [False] * n stack = deque([s]) while stack: now = stack.pop() check[now] = True for next in graph[now]: if check[next]: continue k -= 1 cnt += 1 if k == 1: print(cnt) exit() stack.appendleft(next) dfs(0) print(-1)