#include using namespace std; int main() { int N,M; cin>>N>>M; vector> G(N); for(int i=0;i>a>>b; a--; b--; G[a].push_back(b); G[b].push_back(a); } vector dist(N,-1); dist[0] = 0; queue q; q.push(0); while(!q.empty()){ int pos = q.front(); q.pop(); for(int x:G[pos]){ if(dist[x] != -1) continue; q.push(x); dist[x] = dist[pos] + 1; } } cout<