#include <iostream>

using namespace std;

const int MAX = 1001;
int n, m;
char matrica[MAX][MAX];

void DFSS(int i, int j) {
	if (i<0 or i>=n or j<0 or j>=m or matrica[i][j]=='*' or matrica[i][j]=='X') {
		return;
	}
	matrica[i][j] = 'S';
	DFSS(i, j + 1);
	DFSS(i, j - 1);
	DFSS(i + 1, j);
	DFSS(i - 1, j);
}
void DFSX(int i, int j) {
	if (i<0 or i>=n or j<0 or j>=m or matrica[i][j] == '*' or matrica[i][j] == 'S') {
		return;
	}
	matrica[i][j] = 'X';
	DFSX(i, j + 1);
	DFSX(i, j - 1);
	DFSX(i + 1, j);
	DFSX(i - 1, j);
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> matrica[i][j];
		}
	}
	int brojac = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (matrica[i][j] == 'S') {
				DFSS(i, j);
				brojac++;
			}if (matrica[i][j] == 'X') {
				DFSX(i, j);
			}
		}
	}
	cout << brojac;
	return 0;
}