#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?", ":"")<; void bfs(int& n, int& k, const vector>& g) { queue

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