// Arup Guha
// 3/2/2024
// Solution to Kattis Problem Counting Stars

import java.util.*;

public class countingstars {

	final public static int[] DX = {-1,0,0,1};
	final public static int[] DY = {0,-1,1,0};
	
	public static int r;
	public static int c;
	public static char[][] grid;
	public static int[][] dist;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int loop = 1;
		
		while (stdin.hasNext()) {
		
			r = stdin.nextInt();
			c = stdin.nextInt();
			
			// Read in the grid of characters.
			grid = new char[r][];
			for (int i=0; i<r; i++)
				grid[i] = stdin.next().toCharArray();
				
			// Finding each new star.
			int res = 0;
			for (int i=0; i<r; i++) {
				for (int j=0; j<c; j++) {
					if (grid[i][j] == '-') {
						res++;
						bfs(i, j);
					}
				}
			}
			
			// Ta da!
			System.out.println("Case "+loop+": "+res);
			loop++;
		}
	}
	
	// Runs BFS from (sx, sy);
	public static void bfs(int sx, int sy) {

		grid[sx][sy] = '#';
		
		// Set up my queue.
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		q.offer(sx*c + sy);
		
		// Run BFS.
		while (q.size() > 0) {
		
			// Get next place.
			int cur = q.poll();
			
			// Extract location.
			int x = cur/c;
			int y = cur%c;
			
			// Try going in each direction.
			for (int i=0; i<DX.length; i++) {
			
				int nx = x + DX[i];
				int ny = y + DY[i];
				
				// Can't go off the grid.
				if (!inbounds(nx, ny)) continue;
				
				// Illegal square.
				if (grid[nx][ny] == '#') continue;
				
				// Add to queue mark out.
				grid[nx][ny] = '#';
				q.offer(nx*c + ny);
			}
		}
	}
	
	public static boolean inbounds(int x, int y) {
		return x>=0 && x<r && y>=0 && y<c;
	}
	
	

}