import sys

sys.setrecursionlimit(180000)



def dfs(i,j):

    for m in move:

        ni = i + m[0]

        nj = j + m[1]

        if ni < 0 or ni >= H or nj < 0 or nj >= W:

            continue

        if ch[ni][nj]:

            continue

        if X[i][j] == X[ni][nj]:

            continue

            

        ch[ni][nj] = 1

        K[(ni+nj)%2] += 1

        dfs(ni, nj)

        

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

X = [[[0, 1][a=="#"] for a in eval(input())] for i in range(H)]

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

    

move = [[0,1], [0,-1], [1,0], [-1,0]]



K = [0, 0]

ans = 0

for i in range(H):

    for j in range(W):

        if ch[i][j] > 0:

            continue

        ch[i][j] = 1

        K = [0, 0]

        K[(i+j)%2] = 1

        dfs(i, j)

        ans += K[0] * K[1]

        

print(ans)



from collections import deque



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

X = [[[0, 1][a=="#"] for a in eval(input())] for i in range(H)]



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

move = [[-1,0], [1,0], [0,-1], [0,1]]

ans = 0

for i in range(H):

    for j in range(W):

        if ch[i][j]:

            continue

            

        q = deque([[i,j]])

        a = [0, 0]

        while q:

            t = q.popleft()

            x = t[0]

            y = t[1]

            ch[x][y] = 1

            a[(x+y)%2] += 1

            for m in move:

                nx = x + m[0]

                ny = y + m[1]

                if nx >= 0 and nx < H and ny >= 0 and ny < W and X[x][y] != X[nx][ny]:

                    if ch[nx][ny] == 0:

                        q.append([nx,ny])

                        ch[nx][ny] = 1

        ans += a[0] * a[1]



print(ans)
import sys

sys.setrecursionlimit(180000)


def dfs(i, j):
    for m in move:
        ni = i + m[0]
        nj = j + m[1]
        if ni < 0 or ni >= H or nj < 0 or nj >= W:
            continue
        if ch[ni][nj]:
            continue
        if X[i][j] == X[ni][nj]:
            continue
        ch[ni][nj] = 1
        K[(ni + nj) % 2] += 1
        dfs(ni, nj)


H, W = list(map(int, input().split()))
X = [[[0, 1][a == "#"] for a in eval(input())] for i in range(H)]
ch = [[0] * W for _ in range(H)]
move = [[0, 1], [0, -1], [1, 0], [-1, 0]]
K = [0, 0]
ans = 0
for i in range(H):
    for j in range(W):
        if ch[i][j] > 0:
            continue
        ch[i][j] = 1
        K = [0, 0]
        K[(i + j) % 2] = 1
        dfs(i, j)
        ans += K[0] * K[1]
print(ans)

from collections import deque

H, W = list(map(int, input().split()))
X = [[[0, 1][a == "#"] for a in eval(input())] for i in range(H)]
ch = [[0] * W for _ in range(H)]
move = [[-1, 0], [1, 0], [0, -1], [0, 1]]
ans = 0
for i in range(H):
    for j in range(W):
        if ch[i][j]:
            continue
        q = deque([[i, j]])
        a = [0, 0]
        while q:
            t = q.popleft()
            x = t[0]
            y = t[1]
            ch[x][y] = 1
            a[(x + y) % 2] += 1
            for m in move:
                nx = x + m[0]
                ny = y + m[1]
                if nx >= 0 and nx < H and ny >= 0 and ny < W and X[x][y] != X[nx][ny]:
                    if ch[nx][ny] == 0:
                        q.append([nx, ny])
                        ch[nx][ny] = 1
        ans += a[0] * a[1]
print(ans)

-import sys - -sys.setrecursionlimit(180000) - - -def dfs(i, j): -    for m in move: -        ni = i + m[0] -        nj = j + m[1] -        if ni < 0 or ni >= H or nj < 0 or nj >= W: -            continue -        if ch[ni][nj]: -            continue -        if X[i][j] == X[ni][nj]: -            continue -        ch[ni][nj] = 1 -        K[(ni + nj) % 2] += 1 -        dfs(ni, nj) - +from collections import deque -move = [[0, 1], [0, -1], [1, 0], [-1, 0]] -K = [0, 0] +move = [[-1, 0], [1, 0], [0, -1], [0, 1]] -        if ch[i][j] > 0: +        if ch[i][j]: -        ch[i][j] = 1 -        K = [0, 0] -        K[(i + j) % 2] = 1 -        dfs(i, j) -        ans += K[0] * K[1] +        q = deque([[i, j]]) +        a = [0, 0] +        while q: +            t = q.popleft() +            x = t[0] +            y = t[1] +            ch[x][y] = 1 +            a[(x + y) % 2] += 1 +            for m in move: +                nx = x + m[0] +                ny = y + m[1] +                if nx >= 0 and nx < H and ny >= 0 and ny < W and X[x][y] != X[nx][ny]: +                    if ch[nx][ny] == 0: +                        q.append([nx, ny]) +                        ch[nx][ny] = 1 +        ans += a[0] * a[1]