#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=10000+5;
int low[maxn],pre[maxn];
int dfs_clock;
int cut[maxn];
vector<int> G[maxn];
int n,m;
struct node{
int cut,idx;
node(int cut,int idx):cut(cut),idx(idx) {}
bool operator < (const node &rhs) const {
if(cut!=rhs.cut) return cut>rhs.cut;
return idx<rhs.idx;
}
};
vector<node> ans;
int dfs_cut(int u,int fa)
{
int lowu=pre[u]=++dfs_clock;
int child=0;
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i];
if(!pre[v])
{
child++;
int lowv=dfs_cut(v,u);
lowu=min(lowu,lowv);
if(lowv>=pre[u])
cut[u]++;//这里可以记录这个割点连接了几个连通块
}
else if(pre[v]<pre[u]&&v!=fa)
lowu=min(lowu,pre[v]);
}
if(fa<0&&child==1) cut[u]=1;
low[u]=lowu;
return lowu;
}
int main()
{
while(scanf("%d%d",&n,&m)&&(n+m))
{
ans.clear();
for(int i=0;i<n;i++) G[i].clear();
int u,v;
while(scanf("%d%d",&u,&v)&&(u!=-1&&v!=-1))
{
G[u].push_back(v);
G[v].push_back(u);
}
dfs_clock=0;
memset(pre,0,sizeof(pre));
memset(low,0,sizeof(low));
memset(cut,false,sizeof(cut));
dfs_cut(0,-1);
for(int i=1;i<n;i++) cut[i]++;
for(int i=0;i<=n;i++) {
ans.push_back(node(cut[i],i));
}
sort(ans.begin(),ans.end());
for(int i=0;i<m;i++){cout<<ans[i].idx<<" "<<ans[i].cut<<endl;}
printf("\n");
}
return 0;
}
08-25