// Arup Guha
// 2/22/2025
// Solution to Kattis Problem: Seba's Amoebas

import java.util.*;

public class amoebas {

	public static int r;
	public static int c;
	//public static char[][] grid;

	// Directions of movement.
	final public static int[] DX = {-1,-1,-1,0,0,1,1,1};
	final public static int[] DY = {-1,0,1,-1,1,-1,0,1};
	
	public static void main(String[] args) {
	
		// Get size of grid.
		Scanner stdin = new Scanner(System.in);
		r = stdin.nextInt();
		c = stdin.nextInt();
		
		// Read grid.
		char[][] grid = new char[r][c];
		for (int i=0; i<r; i++)
			grid[i] = stdin.next().toCharArray();
		
		// Will store where we've visited.
		boolean[][] used = new boolean[r][c];
		
		// Store result here.
		int res = 0;
		
		for (int i=0; i<r; i++) {
			for (int j=0; j<c; j++) {
			
				// Either we've marked it or it's not a loop.
				if (used[i][j] || grid[i][j] != '#') continue;
				
				// Add to tally and recursively mark loop.
				res++;
				fill(grid, i, j, used);
			}
		}
		
		// Ta da!
		System.out.println(res);
	}
	
	public static void fill(char[][] grid, int x, int y, boolean[][] used) {
		
		// Reasons not to mark it.
		if (!inbounds(x, y)) return;
		if (grid[x][y] != '#') return;
		if (used[x][y]) return;
		
		// Mark it.
		used[x][y] = true;
		
		// Recurse on neigbors.
		for (int i=0; i<DX.length; i++) 
			fill(grid, x+DX[i], y+DY[i], used);
	}
	
	public static boolean inbounds(int x, int y) {
		return x>=0 && x<r && y>=0 && y<c;
	}
}