import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); Map> graph = new HashMap<>(); for(int i = 1; i <= n; i++) graph.put(i, new ArrayList<>()); for(int i = 0; i < n-1; i++) { int a = sc.nextInt(); int b = sc.nextInt(); graph.get(a).add(b); graph.get(b).add(a); } Queue queue = new LinkedList<>(); queue.offer(1); Set visited = new HashSet<>(); visited.add(1); k--; int steps = 0; if(k == 0) { System.out.println(steps); return; } while(!queue.isEmpty()) { int node = queue.poll(); List adj = graph.get(node); for(int adjNode : adj) { if(visited.contains(adjNode)) continue; visited.add(adjNode); queue.offer(adjNode); k--; steps++; if(k == 0) { System.out.println(steps); return; } } } System.out.println(-1); } }