#include using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cout; using std::cerr; using std::endl; using std::cin; template std::vector make_v(size_t a){return std::vector(a);} template auto make_v(size_t a,Ts... ts){ return std::vector(ts...))>(a,make_v(ts...)); } int main() { int n, k; scanf("%d%d", &n, &k); std::vector a(n), b(n); std::vector> g(n); for(int i = 0; i < n - 1; i++) { scanf("%d%d", &a[i], &b[i]); a[i]--; b[i]--; g[a[i]].push_back(i); g[b[i]].push_back(i); } if(n < k) { printf("-1\n"); return 0; } k--; i64 ans = 0; std::queue qu({0}); std::vector used(n, false); used[0] = true; while(!qu.empty() and k) { int v = qu.front(); qu.pop(); for(int id: g[v]) { int to = a[id] ^ b[id] ^ v; if(used[to]) continue; used[to] = true; ans++; if(!(--k)) break; qu.push(to); } } printf("%ld\n", ans); return 0; }