#include <cstdlib> #include <iostream> #include <cstdio> using namespace std; const int MAX = 50001; int parent[MAX]; int num[MAX]; int maxNum = 0; void initUnion(int count) { for(int i=0; i<count; i++) { parent[i] = i; num[i] = 1; } } int findElem(int x) { int y = x, temp; while(parent[y] != y) y = parent[y]; while(x != y) { temp = parent[x]; parent[x] = y; x = temp; } return y; } void unionElem(int a, int b) { int x = findElem(a); int y = findElem(b); if(x == y) return; if(num[x] <= num[y]) { parent[x] = y; num[y] += num[x]; maxNum--; } else { parent[y] = x; num[x] += num[y]; maxNum--; } } int main(int argc, char *argv[]) { int n, m, index = 1; //freopen("input.txt", "rt", stdin); //freopen("output.txt", "wt", stdout); while(scanf("%d%d", &n, &m) && n != 0) { int x, y; maxNum = n; initUnion(n); while(m-- > 0) { scanf("%d%d", &x, &y); unionElem(x, y); } cout << "Case " << index++ << ": " << maxNum << endl; } return EXIT_SUCCESS; }