import itertools

H, W = [int(_) for _ in input().split()]

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

is_searched = [[False for _ in range(W)] for _ in range(H)]





def dfs(p, q):

    if is_searched[p][q] == 1:

        return 0

    count = {'#': 0, '.': 0}

    que = [[p, q]]

    while que:

        x, y = que.pop(0)

        if is_searched[x][y] != 1:

            is_searched[x][y] = 1

            count[S[x][y]] += 1

            dxy = [[-1, 0], [1, 0], [0, -1], [0, 1]]

            for dx, dy in dxy:

                nx, ny = x + dx, y + dy

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

                    que += [[nx, ny]]

    return count['#'] * count['.']





print((sum([dfs(i, j) for i, j in itertools.product(list(range(H)), list(range(W)))])))

import itertools

H, W = [int(_) for _ in input().split()]

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

is_searched = [[False for _ in range(W)] for _ in range(H)]





def dfs(p, q):

    if is_searched[p][q] == 1:

        return 0

    count = {'#': 0, '.': 0}

    stack = [[p, q]]

    while stack:

        x, y = stack.pop()

        if is_searched[x][y] != 1:

            is_searched[x][y] = 1

            count[S[x][y]] += 1

            dxy = [[-1, 0], [1, 0], [0, -1], [0, 1]]

            for dx, dy in dxy:

                nx, ny = x + dx, y + dy

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

                    stack += [[nx, ny]]

    return count['#'] * count['.']





print((sum([dfs(i, j) for i, j in itertools.product(list(range(H)), list(range(W)))])))

import itertools

H, W = [int(_) for _ in input().split()]
S = [eval(input()) for _ in range(H)]
is_searched = [[False for _ in range(W)] for _ in range(H)]


def dfs(p, q):
    if is_searched[p][q] == 1:
        return 0
    count = {"#": 0, ".": 0}
    que = [[p, q]]
    while que:
        x, y = que.pop(0)
        if is_searched[x][y] != 1:
            is_searched[x][y] = 1
            count[S[x][y]] += 1
            dxy = [[-1, 0], [1, 0], [0, -1], [0, 1]]
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and S[x][y] != S[nx][ny]:
                    que += [[nx, ny]]
    return count["#"] * count["."]


print((sum([dfs(i, j) for i, j in itertools.product(list(range(H)), list(range(W)))])))

import itertools

H, W = [int(_) for _ in input().split()]
S = [eval(input()) for _ in range(H)]
is_searched = [[False for _ in range(W)] for _ in range(H)]


def dfs(p, q):
    if is_searched[p][q] == 1:
        return 0
    count = {"#": 0, ".": 0}
    stack = [[p, q]]
    while stack:
        x, y = stack.pop()
        if is_searched[x][y] != 1:
            is_searched[x][y] = 1
            count[S[x][y]] += 1
            dxy = [[-1, 0], [1, 0], [0, -1], [0, 1]]
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and S[x][y] != S[nx][ny]:
                    stack += [[nx, ny]]
    return count["#"] * count["."]


print((sum([dfs(i, j) for i, j in itertools.product(list(range(H)), list(range(W)))])))

-    que = [[p, q]] -    while que: -        x, y = que.pop(0) +    stack = [[p, q]] +    while stack: +        x, y = stack.pop() -                    que += [[nx, ny]] +                    stack += [[nx, ny]]