#include <iostream>
using namespace std;
#include<vector>
#include <bits/stdc++.h>
int main() {
// your code goes here
int n,m;
cin>>n>>m;
vector<int>g[n+5];
int x,y;
for(int i=1;i<=m;i++)
{
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
int source=1;
int used[n+5]={0};
int level[n+5]={0};
queue<int>q;
q.push(source);
used[source]=1;
level[source]=0;
while(!q.empty())
{
int removed;
removed = q.front();
cout<<removed<<"-"<<level[removed]<<endl;
q.pop();
for(auto x:g[removed])
{
if(used[x]==0)
{
q.push(x);
}
used[x]=1;
level[x]=level[removed]+1;
}
}
i=1;
//while(i<=n) For each input graph print the shortest distance of each node from the source node.
//{ serial wise...
// cout<<level[i]<<" ";
//}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojaW5jbHVkZTx2ZWN0b3I+CiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgppbnQgbWFpbigpIHsKCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKCWludCBuLG07CgljaW4+Pm4+Pm07Cgl2ZWN0b3I8aW50Pmdbbis1XTsKCQoJaW50IHgseTsKCWZvcihpbnQgaT0xO2k8PW07aSsrKQoJIHsKCSAJY2luPj54Pj55OwoJIAlnW3hdLnB1c2hfYmFjayh5KTsKCSAJZ1t5XS5wdXNoX2JhY2soeCk7CgkgfQoJIGludCBzb3VyY2U9MTsKCSBpbnQgdXNlZFtuKzVdPXswfTsKCSBpbnQgbGV2ZWxbbis1XT17MH07CgkgcXVldWU8aW50PnE7CgkgcS5wdXNoKHNvdXJjZSk7CgkgdXNlZFtzb3VyY2VdPTE7CgkgbGV2ZWxbc291cmNlXT0wOwoJIHdoaWxlKCFxLmVtcHR5KCkpCgkgIHsKCSAgCWludCByZW1vdmVkOwoJICAJcmVtb3ZlZCA9IHEuZnJvbnQoKTsKCSAgICBjb3V0PDxyZW1vdmVkPDwiLSI8PGxldmVsW3JlbW92ZWRdPDxlbmRs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