#include <bits/stdc++.h>
using namespace std;
struct node
{
int x, y;
};
int n, m;
string s[10005];
int dir[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, 1, 1, -1, 1, 1, -1, -1, -1};
void bfs(int x, int y)
{
queue<node> q;
q.push((node){x, y});
s[x][y] = '.';
while (!q.empty())
{
node u = q.front();
q.pop();
for (int i = 0; i < 8; i++)
{
int xx = u.x + dir[i][0];
int yy = u.y + dir[i][1];
if (xx >= 0 && xx < n && yy >= 0 && yy < m && s[xx][yy] != '.')
{
s[xx][yy] = '.';
q.push((node){xx, yy});
}
}
}
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> s[i];
int ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (s[i][j] != '.')
{
bfs(i, j);
ans++;
}
cout << ans;
return 0;
}