import java.util.Scanner;
public class Main {
public static Scanner cin = new Scanner(System.in);
static int[][] dir = { { -1, 0 }, { -1, -1 }, { 0, -1 }, { 1, -1 }, { 1, 0 }, { 1, 1 }, { 0, 1 }, { -1, 1 } };
static int N = 105;
static int n, m;
static char[][] map = new char[N][N];
static int cnt;
public static boolean in(int x, int y) {
return 0 <= x && x < n && 0 <= y && y < m;
}
public static void dfs(int x, int y) {
map[x][y] = '.';
for (int i = 0; i < 8; i++) {
int tx = x + dir[i][0];
int ty = y + dir[i][1];
if (in(tx, ty) && map[tx][ty] == 'W')
dfs(tx, ty);
}
}
public static void main(String[] args) {
n = cin.nextInt();
m = cin.nextInt();
for (int i = 0; i < n; i++)
map[i] = cin.next().toCharArray();
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (map[i][j] == 'W') {
cnt++;
dfs(i, j);
}
System.out.println(cnt);
}
}