#include <iostream>
#include <map>
#include <cstdio>
using namespace std;
//并查集
int fa[50008];
int find(int a)
{
if(a!=fa[a])
{
return find(fa[a]);
}else
{
return a;
}
}
int main()
{
int js=0;
while(1)
{
js++;
int n,m;
//cin>>n>>m;
scanf("%d %d",&n,&m);
if(n==m && n==0)
{
break;
}
for(int i=1;i<=n;i++)
{
fa[i]=i;
}
for(int o=0;o<m;o++)
{
int x,y;
//cin>>x>>y;
scanf("%d %d",&x,&y);
if(find(x)!=find(y))
{
fa[find(x)]=find(y);
}
}
map<int,int> mp;
mp.clear();
for(int i=1;i<=n;i++)
{
int t=find(i);
mp[t]++;
}
printf("Case %d: %d\n",js,mp.size());
//cout<<"Case "<<js<<": "<<mp.size()<<endl;
}
return 0;
}