import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

int[] di = [1, 0, -1, 0];
int[] dj = [0, 1, 0, -1];

void main() {
    int h, w;
    scan(h, w);
    auto ban = iota(h).map!(i => readln.chomp).array;

    int black, white;
    auto visited = new bool[][](h, w);

    // 0 : #, 1 : .
    void dfs(int i, int j, int bh) {
        visited[i][j] = true;
        if (bh) {
            white++;
        }
        else {
            black++;
        }

        foreach (k ; 0 .. 4) {
            int ni = i + di[k];
            int nj = j + dj[k];

            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (visited[ni][nj]) continue;
            if (bh && ban[ni][nj] != '#') continue;
            if (!bh && ban[ni][nj] != '.') continue;
            dfs(ni, nj, bh ^ 1);
        }
    }

    long ans;

    foreach (i ; 0 .. h) {
        foreach (j ; 0 .. w) {
            if (ban[i][j] == '#' && !visited[i][j]) {
                black = white = 0;
                dfs(i, j, 0);
                debug {
                    writefln("%(%(%b %)\n%)", visited);
                }
                debug {
                    writefln("(%d, %d), %d, %d", i, j, black, white);
                }
                ans += 1L * black * white;
            }
        }
    }

    writeln(ans);
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg ; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg ; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

long powmod(long x, long y, long mod = 1_000_000_007L) {
    long res = 1L;

    while (y > 0) {
        if (y & 1) {
            (res *= x) %= mod;
        }
        (x *= x) %= mod;
        y >>= 1;
    }

    return res;
}