#include #include #include using namespace std; int N,M; vectorG[2<<17]; int dist[2<<17]; main() { cin>>N>>M; for(int i=0;i>a>>b; a--,b--; G[a].push_back(b); G[b].push_back(a); } for(int i=1;iP; P.push(0); while(!P.empty()) { int u=P.front();P.pop(); for(int v:G[u])if(dist[v]>dist[u]+1) { dist[v]=dist[u]+1; P.push(v); } } if(dist[N-1]==M+1)cout<<-1<