import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto H = tokens[0].to!ulong();
	auto W = tokens[1].to!ulong();
	string[] S;
	foreach (i; 0..H)
	{
		S ~= my_readln();
	}

	uint f(uint x, uint y)
	{
		uint[2][] open;
		open ~= [x, y];
		uint[][] close;
		close.length = H;
		foreach (ref e; close) e.length = W;

		while (open.length != 0)
		{
			auto node = open.front;
			open.popFront;

			uint i = node[0], j = node[1];
			auto c = S[i][j];
			if (i != 0 && !close[i-1][j] && S[i-1][j] != c)
			{
				open ~= [i-1, j];
				close[i-1][j] = 1;
			}
			else if (i != H - 1 && !close[i+1][j] && S[i+1][j] != c)
			{
				open ~= [i+1, j];
				close[i+1][j] = 1;
			}
			if (j != 0 && !close[i][j-1] && S[i][j-1] != c)
			{
				open ~= [i, j-1];
				close[i][j-1] = 1;
			}
			else if (j != W - 1 && !close[i][j+1] && S[i][j+1] != c)
			{
				open ~= [i, j+1];
				close[i][j+1] = 1;
			}
		}

		uint cnt;
		foreach (i; 0..H)
		{
			foreach (j; 0..W)
			{
				if (close[i][j] && S[i][j] == '.')
					++cnt;
			}
		}
		return cnt;
	}

	uint ans;
	foreach (i; 0..H)
	{
		foreach (j; 0..W)
		{
			if (S[i][j] == '#')
				ans += f(cast(uint)i, cast(uint)j);
		}
	}

	writeln(ans);
	stdout.flush();
	/*}catch (Throwable e)
	{
	writeln(e.toString());
	}
	readln();*/
}