#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; } std::queue qu({0}); std::vector dist(n, -1); dist[0] = 0; while(!qu.empty()) { auto v = qu.front(); qu.pop(); for(int id: g[v]) { int to = a[id] ^ b[id] ^ v; if(dist[to] != -1) continue; dist[to] = dist[v] + 1; qu.push(to); } } sort(begin(dist), end(dist)); i64 ans = 0; for(int i = 0; i < k; i++) ans += dist[i]; printf("%ld\n", ans); return 0; }