void main()
{
    long h, w;
    rdVals(h, w);
    string[] s = h.rdCol!string;

    bool[][] seen = new bool[][](h, w);
    long[] dely = [-1, 0, 1, 0], delx = [0, 1, 0, -1];
    long result;
    void bfs(long y, long x)
    {
        Grid[] que;
        que ~= Grid(y, x);
        seen[y][x] = true;
        long black, white;
        if (s[y][x] == '#') ++black;
        else ++white;
        while (!que.empty)
        {
            Grid now = que.front;
            que.popFront;
            foreach (dy, dx; zip(dely, delx))
            {
                Grid nxt = now;
                nxt.y += dy, nxt.x += dx;
                if (nxt.y < 0 || h <= nxt.y || nxt.x < 0 || w <= nxt.x) continue;
                if (seen[nxt.y][nxt.x]) continue;
                if (s[nxt.y][nxt.x] == s[now.y][now.x]) continue;

                que ~= nxt;
                seen[nxt.y][nxt.x] = true;
                if (s[nxt.y][nxt.x] == '#') ++black;
                else ++white;
            }
        }
        result += black * white;
    }

    foreach (i; 0 .. h)
    {
        foreach (j; 0 .. w)
        {
            if (!seen[i][j]) bfs(i, j);
        }
    }

    result.writeln;
}

struct Grid
{
    long y, x;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;