//7956395 vrs 2524 Accepted 536K 344MS C 1280B 2010-12-02 17:33:55
//POJ 2524 学生宗教 并查集基础题
#include<stdio.h>
unsigned int setFarther[50005];
unsigned int setLevel[50005];
void MakeSet(unsigned int n)
{
unsigned int i;
for(i=1;i<=n;i++)
{
setFarther[i]=i;
setLevel[i]=1;
}
}
unsigned int Find(unsigned int x)
{
unsigned int temp,root;
temp=x;
while(setFarther[temp]!=temp)
temp=setFarther[temp];
root=temp;
/*
temp=x;
while(setFarther[temp]!=temp)
{
setFarther[temp]=root;
temp=setFarther[temp];
}*/
return root;
}
void UnionSet(unsigned int i,unsigned int j)
{
unsigned int rootA;
unsigned int rootB;
rootA=Find(i);
rootB=Find(j);
if(setLevel[rootA]==setLevel[rootB])
{
setFarther[rootB]=rootA;
setLevel[rootA]++;
}
else if(setLevel[rootA]>setLevel[rootB])
{
setFarther[rootB]=rootA;
setLevel[rootA]++;
}
else
{
setFarther[rootA]=rootB;
setLevel[rootB]++;
}
}
int main()
{
unsigned int n;
unsigned long m;
unsigned int a,b,i;
unsigned int count;
int testcase=1;
while(scanf("%d %d",&n,&m) && !(n==0 && m==0))
{
MakeSet(n);
for(i=1;i<=m;i++)
{
scanf("%d %d",&a,&b);
UnionSet(a,b);
}
count=0;
for(i=1;i<=n;i++)
if(setFarther[i]==i)
count++;
printf("Case %d: %d\n",testcase++,count);
}
return 0;
}