#include <iostream>

using namespace std;

const int MAX = 1001;

void DFSS(int i, int j, int n, int m, char matrica[MAX][MAX]) {
	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, n, m, matrica);
	DFSS(i, j - 1, n, m, matrica);
	DFSS(i + 1, j, n, m, matrica);
	DFSS(i - 1, j, n, m, matrica);
}
void DFSX(int i, int j, int n, int m, char matrica[MAX][MAX]) {
	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, n, m, matrica);
	DFSX(i, j - 1, n, m, matrica);
	DFSX(i + 1, j, n, m, matrica);
	DFSX(i - 1, j, n, m, matrica);
}

int main()
{
	int n, m;
	char matrica[MAX][MAX];
	
	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, n, m, matrica);
				brojac++;
			}if (matrica[i][j] == 'X') {
				DFSX(i, j, n, m, matrica);
			}
		}
	}
	cout << brojac;
	return 0;
}