program atcoder
    implicit none
    integer(8) :: i,j,w,h,a,b,ans=0
    integer,allocatable,dimension(:,:) :: did
    character(len=401) :: s(401)

    read*,h,w
    allocate(did(h,w))
    did = 0

    do i=1,h
        read(*,*)s(i)
    enddo

    do i = 1,h
        do j = 1,w
            a=0
            b=0
            if(did(i,j)==0)then
                call dfs(i,j)
                ans = ans + a*b
            endif
        enddo
    enddo
    write(*,'(I0)')ans

    stop 
contains

recursive subroutine dfs(x,y)
    implicit none
    integer(8) :: x,y
    did(x,y) = 1
    if(s(x)(y:y)=='#')then
        b = b+1;
    else
        a = a+1;
    endif
    if(x>1 .and. did(x-1,y)==0 .and. s(x)(y:y)/=s(x-1)(y:y))Then
        call dfs(x-1,y)
    endif
    if(x<h .and. did(x+1,y)==0 .and. s(x)(y:y)/=s(x+1)(y:y))Then
        call dfs(x+1,y)
    endif
    if(y>1 .and. did(x,y-1)==0 .and. s(x)(y:y)/=s(x)(y-1:y-1))Then
        call dfs(x,y-1)
    endif
    if(y<w .and. did(x,y+1)==0 .and. s(x)(y:y)/=s(x)(y+1:y+1))Then
        call dfs(x,y+1)
    endif
end subroutine dfs

end program atcoder
