#include <iostream>
#include <vector>
#include <set>
#include <string>
using namespace std;
int n, m;
vector<vector<bool>> la;
set<pair<int, int>> wall;
bool valid(int i, int j) {
return i >= 0 && i < n && j >= 0 && j < m && !la[i][j] && wall.find({i, j}) == wall.end();
}
void dfs(int i, int j) {
if (!valid(i, j)) return;
la[i][j] = true;
dfs(i + 1, j);
dfs(i - 1, j);
dfs(i, j + 1);
dfs(i, j - 1);
}
int main() {
cin >> n >> m;
la.resize(n, vector<bool>(m, false));
vector<vector<int>> a(n, vector<int>(m, 0));
string ch;
for (int i = 0; i < n; i++) {
cin >> ch;
for (int j = 0; j < m; j++) {
if (ch[j] == '#') {
a[i][j] = 1;
wall.insert({i, j});
} else {
a[i][j] = 0;
}
}
}
int nb = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!la[i][j] && wall.find({i, j}) == wall.end()) {
dfs(i, j);
nb++;
}
}
}
cout << nb << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG4sIG07CnZlY3Rvcjx2ZWN0b3I8Ym9vbD4+IGxhOwpzZXQ8cGFpcjxpbnQsIGludD4+IHdhbGw7Cgpib29sIHZhbGlkKGludCBpLCBpbnQgaikgewogICAgcmV0dXJuIGkgPj0gMCAmJiBpIDwgbiAmJiBqID49IDAgJiYgaiA8IG0gJiYgIWxhW2ldW2pdICYmIHdhbGwuZmluZCh7aSwgan0pID09IHdhbGwuZW5kKCk7Cn0KCnZvaWQgZGZzKGludCBpLCBpbnQgaikgewogICAgaWYgKCF2YWxpZChpLCBqKSkgcmV0dXJuOwogICAgbGFbaV1bal0gPSB0cnVlOwogICAgZGZzKGkgKyAxLCBqKTsKICAgIGRmcyhpIC0gMSwgaik7CiAgICBkZnMoaSwgaiArIDEpOwogICAgZGZzKGksIGogLSAxKTsKfQoKaW50IG1haW4oKSB7CiAgICBjaW4gPj4gbiA+PiBtOwoKICAgIGxhLnJlc2l6ZShuLCB2ZWN0b3I8Ym9vbD4obSwgZmFsc2UpKTsKICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gYShuLCB2ZWN0b3I8aW50PihtLCAwKSk7CgogICAgc3RyaW5nIGNoOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICBjaW4gPj4gY2g7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBtOyBqKyspIHsKICAgICAgICAgICAgaWYgKGNoW2pdID09ICcjJykgewogICAgICAgICAgICAgICAgYVtpXVtqXSA9IDE7CiAgICAgICAgICAgICAgICB3YWxsLmluc2VydCh7aSwgan0pOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgYVtpXVtqXSA9IDA7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgaW50IG5iID0gMDsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBtOyBqKyspIHsKICAgICAgICAgICAgaWYgKCFsYVtpXVtqXSAmJiB3YWxsLmZpbmQoe2ksIGp9KSA9PSB3YWxsLmVuZCgpKSB7CiAgICAgICAgICAgICAgICBkZnMoaSwgaik7CiAgICAgICAgICAgICAgICBuYisrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIGNvdXQgPDwgbmIgPDwgZW5kbDsKICAgIHJldHVybiAwOwp9Cg==