import sys

sys.setrecursionlimit(10**6)



H,W = list(map(int,input().split()))

grid = [["&"] * (W+2) for i in range(H+2)]

visited = [[False] * (W+2) for i in range(H+2)]

# debug: visited_count = [[0] * (W+2) for i in range(H+2)]

start = []

for i in range(H):

    s = eval(input())

    for j in range(W):

        grid[i+1][j+1] = s[j]



ans = 0

b = 0

w = 0

def dfs(p_i,p_j):

    if visited[p_i][p_j] is True:

        global ans

        return

    visited[p_i][p_j] = True

    if grid[p_i][p_j] == "#":

        # debug: visited_count[p_i][p_j] += 1

        global b

        b += 1

    elif grid[p_i][p_j] == ".":

        # debug: visited_count[p_i][p_j] += 1

        global w

        w += 1

    around = [[p_i,p_j+1],[p_i+1,p_j],[p_i,p_j-1],[p_i-1,p_j]]

    for i,j in around:

        if grid[p_i][p_j] == "#" and grid[i][j] == ".":

            dfs(i,j)

        elif grid[p_i][p_j] == "." and grid[i][j] == "#":

            dfs(i,j)



for i in range(1,H+1):

    for j in range(1,W+1):

        if visited[i][j] is False:

            dfs(i,j)

            ans += b * w

            b = 0

            w = 0



print(ans)



""" debug

print(start)

for line in visited_count:

    print(line)

print("b = {}".format(b))

print("w = {}".format(w)) """
import sys

sys.setrecursionlimit(10**6)



around = [(0,1),(1,0),(0,-1),(-1,0)]



H,W = list(map(int,input().split()))

grid = [list(eval(input())) for _ in range(H)]



checked = [[0]*W for _ in range(H)]



def dfs(i,j):

    checked[i][j] = 1

    for di,dj in around:

        ni = i + di; nj = j + dj

        if not(0 <= ni <= H-1 and 0 <= nj <= W-1):

            continue

        if checked[ni][nj]:

            continue

        p = grid[i][j]

        np = grid[ni][nj]

        if (p,np) == (".","#"):

            global b

            b += 1

            dfs(ni,nj)

        if (p,np) == ("#","."):

            global w

            w += 1

            dfs(ni,nj)



ans = 0

for i in range(H):

    for j in range(W):

        b = 0; w = 1

        if not checked[i][j] and grid[i][j] == ".":

            dfs(i,j)

        ans += b*w

print(ans)
import sys

sys.setrecursionlimit(10**6)
H, W = list(map(int, input().split()))
grid = [["&"] * (W + 2) for i in range(H + 2)]
visited = [[False] * (W + 2) for i in range(H + 2)]
# debug: visited_count = [[0] * (W+2) for i in range(H+2)]
start = []
for i in range(H):
    s = eval(input())
    for j in range(W):
        grid[i + 1][j + 1] = s[j]
ans = 0
b = 0
w = 0


def dfs(p_i, p_j):
    if visited[p_i][p_j] is True:
        global ans
        return
    visited[p_i][p_j] = True
    if grid[p_i][p_j] == "#":
        # debug: visited_count[p_i][p_j] += 1
        global b
        b += 1
    elif grid[p_i][p_j] == ".":
        # debug: visited_count[p_i][p_j] += 1
        global w
        w += 1
    around = [[p_i, p_j + 1], [p_i + 1, p_j], [p_i, p_j - 1], [p_i - 1, p_j]]
    for i, j in around:
        if grid[p_i][p_j] == "#" and grid[i][j] == ".":
            dfs(i, j)
        elif grid[p_i][p_j] == "." and grid[i][j] == "#":
            dfs(i, j)


for i in range(1, H + 1):
    for j in range(1, W + 1):
        if visited[i][j] is False:
            dfs(i, j)
            ans += b * w
            b = 0
            w = 0
print(ans)
""" debug
print(start)
for line in visited_count:
    print(line)
print("b = {}".format(b))
print("w = {}".format(w)) """

import sys

sys.setrecursionlimit(10**6)
around = [(0, 1), (1, 0), (0, -1), (-1, 0)]
H, W = list(map(int, input().split()))
grid = [list(eval(input())) for _ in range(H)]
checked = [[0] * W for _ in range(H)]


def dfs(i, j):
    checked[i][j] = 1
    for di, dj in around:
        ni = i + di
        nj = j + dj
        if not (0 <= ni <= H - 1 and 0 <= nj <= W - 1):
            continue
        if checked[ni][nj]:
            continue
        p = grid[i][j]
        np = grid[ni][nj]
        if (p, np) == (".", "#"):
            global b
            b += 1
            dfs(ni, nj)
        if (p, np) == ("#", "."):
            global w
            w += 1
            dfs(ni, nj)


ans = 0
for i in range(H):
    for j in range(W):
        b = 0
        w = 1
        if not checked[i][j] and grid[i][j] == ".":
            dfs(i, j)
        ans += b * w
print(ans)

+around = [(0, 1), (1, 0), (0, -1), (-1, 0)] -grid = [["&"] * (W + 2) for i in range(H + 2)] -visited = [[False] * (W + 2) for i in range(H + 2)] -# debug: visited_count = [[0] * (W+2) for i in range(H+2)] -start = [] -for i in range(H): -    s = eval(input()) -    for j in range(W): -        grid[i + 1][j + 1] = s[j] -ans = 0 -b = 0 -w = 0 +grid = [list(eval(input())) for _ in range(H)] +checked = [[0] * W for _ in range(H)] -def dfs(p_i, p_j): -    if visited[p_i][p_j] is True: -        global ans -        return -    visited[p_i][p_j] = True -    if grid[p_i][p_j] == "#": -        # debug: visited_count[p_i][p_j] += 1 -        global b -        b += 1 -    elif grid[p_i][p_j] == ".": -        # debug: visited_count[p_i][p_j] += 1 -        global w -        w += 1 -    around = [[p_i, p_j + 1], [p_i + 1, p_j], [p_i, p_j - 1], [p_i - 1, p_j]] -    for i, j in around: -        if grid[p_i][p_j] == "#" and grid[i][j] == ".": -            dfs(i, j) -        elif grid[p_i][p_j] == "." and grid[i][j] == "#": -            dfs(i, j) +def dfs(i, j): +    checked[i][j] = 1 +    for di, dj in around: +        ni = i + di +        nj = j + dj +        if not (0 <= ni <= H - 1 and 0 <= nj <= W - 1): +            continue +        if checked[ni][nj]: +            continue +        p = grid[i][j] +        np = grid[ni][nj] +        if (p, np) == (".", "#"): +            global b +            b += 1 +            dfs(ni, nj) +        if (p, np) == ("#", "."): +            global w +            w += 1 +            dfs(ni, nj) -for i in range(1, H + 1): -    for j in range(1, W + 1): -        if visited[i][j] is False: +ans = 0 +for i in range(H): +    for j in range(W): +        b = 0 +        w = 1 +        if not checked[i][j] and grid[i][j] == ".": -            ans += b * w -            b = 0 -            w = 0 +        ans += b * w -""" debug -print(start) -for line in visited_count: -    print(line) -print("b = {}".format(b)) -print("w = {}".format(w)) """