#include<stdio.h>
int p[50006];
int find(int x)
{
if(p[x] == x) return x;
return p[x] = find(p[x]);
}
void Union(int x, int y)
{
p[y] = x; //ans--;
}
int main()
{
int n,m,ans,k = 1;
while(scanf("%d%d",&n,&m))
{ //ans = n;
if(m == 0 && n == 0) break;
for(int i = 1; i <= n; i++) p[i] = i;
for(int i = 0; i < m; i++)
{
int x,y;
scanf("%d%d",&x,&y);
int fx = find(x);
int fy = find(y);
if(fx != fy) Union(fx, fy);
}
ans = 0;
for(int i = 1; i <= n; i++)
if(p[i] == i) ans++;
printf("Case %d: %d\n",k++,ans);
}
return 0;
}
/*
10 9
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
10 4
2 3
4 5
4 8
5 8
0 0
Case 1: 1
Case 2: 7
*/
int p[50006];
int find(int x)
{
if(p[x] == x) return x;
return p[x] = find(p[x]);
}
void Union(int x, int y)
{
p[y] = x; //ans--;
}
int main()
{
int n,m,ans,k = 1;
while(scanf("%d%d",&n,&m))
{ //ans = n;
if(m == 0 && n == 0) break;
for(int i = 1; i <= n; i++) p[i] = i;
for(int i = 0; i < m; i++)
{
int x,y;
scanf("%d%d",&x,&y);
int fx = find(x);
int fy = find(y);
if(fx != fy) Union(fx, fy);
}
ans = 0;
for(int i = 1; i <= n; i++)
if(p[i] == i) ans++;
printf("Case %d: %d\n",k++,ans);
}
return 0;
}
/*
10 9
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
10 4
2 3
4 5
4 8
5 8
0 0
Case 1: 1
Case 2: 7
*/