### BUGGY CODE ###

h,w = map(int,input().split())
lis = [str(input()) for i in range(h)]
ans = 0
ch = [[0] * w for i in range(h)]

def firstcheck(x,y):
    if lis[x][y] != "#" or ch[x][y] != 0:
        return False
    if x > 0:
        if lis[x-1][y] == ".":
            return True
    if x < h-1:
        if lis[x+1][y] == ".":
            return True
    if y > 0:
        if lis[x][y-1] == ".":
            return True
    if y < w-1:
        if lis[x][y+1] == ".":
            return True
    return False

for sx in range(h):
    for sy in range(w):
        if firstcheck(sx,sy):
            cnt = 1
            nu = 0
            ch[sx][sy] = 1
            num = [[0] * w for i in range(h)]
            now = {(sx,sy,1)}
            while now != set():
                tmp = set()
                for x,y,iro in now:
                    if x > 0:
                        if lis[x-1][y] != lis[x][y] and num[x-1][y] == 0:
                            nu += iro
                            tmp.add((x-1,y,(iro+1)%2))
                            num[x-1][y] = 1
                            if lis[x-1][y] == "#" and ch[x-1][y] == 0:
                                cnt += 1
                                ch[x-1][y] = 1
                    if x < h-1:
                        if lis[x+1][y] != lis[x][y] and num[x+1][y] == 0:
                            nu += iro
                            tmp.add((x+1,y,(iro+1)%2))
                            num[x+1][y] = 1
                            if lis[x+1][y] == "#" and ch[x+1][y] == 0:
                                cnt += 1
                                ch[x+1][y] = 1
                    if y > 0:
                        if lis[x][y-1] != lis[x][y] and num[x][y-1] == 0:
                            nu += iro
                            tmp.add((x,y-1,(iro+1)%2))
                            num[x][y-1] = 1
                            if lis[x][y-1] == "#" and ch[x][y-1] == 0:
                                cnt += 1
                                ch[x][y-1] = 1
                    if y < w-1:
                        if lis[x][y+1] != lis[x][y] and num[x][y+1] == 0:
                            nu += iro
                            tmp.add((x,y+1,(iro+1)%2))
                            num[x][y+1] = 1
                            if lis[x][y+1] == "#" and ch[x][y+1] == 0:
                                cnt += 1
                                ch[x][y+1] = 1
                now = tmp
            ans += nu * cnt
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

dxdy = {(-1, 0), (1, 0), (0, -1), (0, 1)}

h,w = map(int,input().split())
s = [str(input()) for i in range(h)]

ch = [[0] * w for i in range(h)]

ans = 0

for i in range(h):
    for j in range(w):
        if ch[i][j] == 0:
            black,white = 0,0
            q = [(i,j)]
            while q:
                y,x = q.pop()
                if ch[y][x] == 0:
                    if s[y][x] == "#":black += 1
                    else:white += 1
                    ch[y][x] = 1
                    for dx,dy in dxdy:
                        if 0 <= x + dx < w and 0 <= y + dy < h and ch[y+dy][x+dx] == 0 and s[y+dy][x+dx] != s[y][x]:
                            q.append((y+dy,x+dx))
            ans += black * white

print(ans)