# Arup Guha
# 2/15/2025
# Counting Stars to illustrate floodfill

import sys

sys.setrecursionlimit(20000)

# Run a flood fill on grid from square (r, c) marking the star connected to it.
def floodfill(grid, marked, r, c):

    # Possible directions of movement.
    DR = [-1,0,0,1]
    DC = [0,-1,1,0]

    # Out of bounds.
    if r < 0 or r >= len(grid) or c < 0 or c >= len(grid[0]):
        return

    # Not a star.
    if grid[r][c] != '-':
        return

    # We've been here before.
    if marked[r][c]:
        return

    # Mark it.
    marked[r][c] = True

    # Recursively fill adjacent squares
    for i in range(len(DR)):
        floodfill(grid, marked, r + DR[i], c + DC[i])

def main():

    # Just get first case.
    toks = input().split()

    loop = 1

    # Will break out.
    while True:

        # Get size of grid.
        numR = int(toks[0])
        numC = int(toks[1])

        # Build grid.
        grid = []
        for i in range(numR):
            grid.append(input().strip())

        # Default to no one visited.
        used = []
        for i in range(numR):
            used.append([False]*numC)
            tmp = []

        # My counter.
        res = 0

        # Go to each square.
        for i in range(numR):
            for j in range(numC):

                # Not a star or already marked.
                if grid[i][j] != '-' or used[i][j]:
                    continue

                # New star.
                res += 1

                # Fill it.
                floodfill(grid, used, i, j)

        # This is their format.
        print("Case ",loop,": ",res, sep="")
        loop += 1

        # Try to get next case.
        try:
            toks = input().split()
        except EOFError:
            break

# Run it.      
main()
