### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    from collections import deque
    H, W = (int(i) for i in input().split())
    c = [input() for i in range(H)]
    seen = [[False]*W for _ in range(H)]
    que = deque()
    for h in range(H):
        for w in range(W):
            if c[h][w] == "#":
                que.append((h, w))

    def bfs(sy, sx):
        if seen[sy][sx]:
            return 0
        dist = [[False]*W for i in range(H)]  # 逆走禁止
        que = deque()
        que.append((sy, sx))
        d = ((1, 0), (0, 1), (-1, 0), (0, -1))
        flag = True  # Trueなら黒マス
        bla = 0
        whi = 0
        while que:
            uh, uw = que.popleft()
            if c[uh][uw] == "#":
                flag = True
                if not(seen[uh][uw]):
                    bla += 1
                    seen[uh][uw] = True
            else:
                flag = False
                if not(seen[uh][uw]):
                    whi += 1
                    seen[uh][uw] = True
            for dy, dx in d:
                next_h = uh + dy
                next_w = uw + dx
                if not(0 <= next_h < H and 0 <= next_w < W):
                    continue
                if dist[next_h][next_w]:
                    continue
                if flag and c[next_h][next_w] == '#':
                    continue
                if not(flag) and c[next_h][next_w] == '.':
                    continue
                dist[next_h][next_w] = True
                que.append((next_h, next_w))
        # print(*seen, sep="\n")
        # print(whi, bla)
        return whi*bla

    ans = 0
    for q in que:
        ans += bfs(q[0], q[1])
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    from collections import deque
    H, W = (int(i) for i in input().split())
    c = [input() for i in range(H)]
    seen = [[False]*W for _ in range(H)]
    que = deque()
    for h in range(H):
        for w in range(W):
            if c[h][w] == "#":
                que.append((h, w))

    def bfs(sy, sx):
        que = deque()
        que.append((sy, sx))
        d = ((1, 0), (0, 1), (-1, 0), (0, -1))
        flag = True  # Trueなら黒マス
        bla = 0
        whi = 0
        while que:
            uh, uw = que.popleft()
            if seen[uh][uw]:
                continue
            if c[uh][uw] == "#":
                flag = True
                bla += 1
                seen[uh][uw] = True
            else:
                flag = False
                whi += 1
                seen[uh][uw] = True
            for dy, dx in d:
                next_h = uh + dy
                next_w = uw + dx
                if not(0 <= next_h < H and 0 <= next_w < W):
                    continue
                if seen[next_h][next_w]:
                    continue
                if flag and c[next_h][next_w] == '#':
                    continue
                if not(flag) and c[next_h][next_w] == '.':
                    continue
                que.append((next_h, next_w))
        return whi*bla

    ans = 0
    for q in que:
        if seen[q[0]][q[1]]:
            continue
        ans += bfs(q[0], q[1])
    print(ans)


if __name__ == '__main__':
    main()