#include <cstdio>
using namespace std;
bool p[103][103], v[103][103];
char s[103];
void dfs(int x, int y)
{
    if (v[x][y] || !p[x][y]) return;
    v[x][y] = true;
    for (int i = -1; i <= 1; i++)
        for (int j = -1; j <= 1; j++)
            dfs(x + i, y + j);
}
int main()
{
    int n, m, ans = 0;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        scanf("%s", s + 1);
        for (int j = 1; j <= m; j++)
            if (s[j] == 'W')
                p[i][j] = true;
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (p[i][j] && !v[i][j])
                ans++, dfs(i, j);
    printf("%d", ans);
    return 0;
}