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

const int[] dr = [0, 0, 1, -1];
const int[] dc = [1, -1, 0, 0];

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = H.iota.map!(_ => readln.chomp).array;
    auto uf = new UnionFind(H*W);

    foreach (r; 0..H) {
        foreach (c; 0..W) {
            foreach (k; 0..4) {
                int nr = r + dr[k];
                int nc = c + dc[k];
                if (nr < 0 || nr >= H || nc < 0 || nc >= W || A[r][c] == A[nr][nc]) continue;
                uf.unite(nr*W+nc, r*W+c);
            }
        }
    }

    long ans = 0;
    auto cnt = new long[][](H*W, 2);

    foreach (i; 0..H*W) {
        int k = uf.find(i);
        cnt[k][A[i/W][i%W]=='#'] += 1;
    }

    foreach (i; 0..H*W) {
        ans += cnt[i][0] * cnt[i][1];
    }

    ans.writeln;
}

class UnionFind {
    int N;
    int[] table;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
    }
}
