#include #include #include #include #include #include #include #include #include #include using namespace std; struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<ostream &operator<<(ostream &o,const vector&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<; int bfs(int& n, int& k, const vector>& g) { int res = 0; vector visited(n+1,false); queue

q; q.emplace(1,0); while(!q.empty() && k > 0) { int u,i; tie(u,i) = q.front(); q.pop(); if (visited[u]) continue; visited[u] = true; k--; res += i; for (auto v : g[u]) { q.emplace(v, i+1); } } return res; } int main() { int n,k; cin >> n >> k; vector> g(n+1); for (int i=0; i> a >> b; g[a].push_back(b); g[b].push_back(a); } int ans = bfs(n, k, g); cout << (k>0? -1 : ans) << endl; }