#include using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; template using V = vector; template using VV = V>; template using VVV = V>; template using VVVV = VV>; #define rep(i,n) for(ll i=0ll;i void chmin(T& t, const U& u) { if (t > u) t = u; } template void chmax(T& t, const U& u) { if (t < u) t = u; } // cin.tie(nullptr); // ios::sync_with_stdio(false); // cout << fixed << setprecision(20); void solve(){ ll n,k; cin >> n >> k; if(n G(n); rep(i,n){ ll a,b; cin >> a >> b; a--; b--; G[a].eb(b); G[b].eb(a); } V dist(n, INF); dist[0] = 0; queue que; que.push(0); while(!que.empty()){ ll nd = que.front(); que.pop(); all(nx, G[nd]) if(dist[nx] > dist[nd]+1){ dist[nx] = dist[nd]+1; que.push(nx); } } sort(be(dist)); ll ans = 0; rep(i, k) ans += dist[i]; cout << ans << endl; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int t=1; // cin >> t; rep(i,t) solve(); }