module UnionFind
    implicit none
    public
        type :: Union_Find
            integer,allocatable,dimension(:) :: par
            integer(8),allocatable,dimension(:) :: g1,g2
        end type Union_Find
    contains
        subroutine init(p,n)
            implicit none
            type(Union_Find)  p
            integer n,i
            allocate( p%par(0:n) )
            allocate( p%g1(0:n) )
            allocate( p%g2(0:n) )
            p%g1 = 0
            p%g2 = 0
            do i=0,n
                p%par(i) = i
            enddo
        end subroutine init
        recursive function root(p,n) result(ret)
            implicit none
            type(Union_Find) p
            integer ret,n
            if(p%par(n)==n)then
                ret = n
                return
            else
                p%par(n) = root(p,p%par(n))
                ret = p%par(n)
                return
            endif
        end
        subroutine unite(p,a,b)
            implicit none
            type(Union_Find) p
            integer a,b
            a = root(p,a)
            b = root(p,b)
            if(a/=b)then
                p%par(a) = b
                p%g1(b) = p%g1(b) + p%g1(a)
                p%g2(b) = p%g2(b) + p%g2(a)
            endif
        end
end module UnionFind

program atcoder
    use UnionFind
    implicit none
    integer :: i,j,w,h,now,to
    integer(8) :: ans=0
    integer,allocatable,dimension(:) :: did
    character(len=401) :: s(401)
    type(Union_Find) uf
    read*,h,w
    do i=1,h
        read(*,*)s(i)
    enddo
    allocate( did(0:(w+1)*(h+1)+1) )
    did = 0
    call init(uf,(h+1)*(w+1)+1)

    do i = 1,h
        do j = 1,w
            if(s(i)(j:j)=='#')then
                uf%g1(w*i+j) = 1
            else 
                uf%g2(w*i+j) = 1
            endif
        enddo
    enddo
    do i = 1,h
        do j = 1,w
            now = w*i+j
            to = w*(i-1)+j
            if(i>1 .and.s(i)(j:j)/=s(i-1)(j:j))then
                call unite(uf,now,to)
            endif
            to = w*(i+1)+j
            if(i<h .and.s(i)(j:j)/=s(i+1)(j:j))then
                call unite(uf,now,to)
            endif 
            to = w*i+j-1
            if(j>1 .and.s(i)(j:j)/=s(i)(j-1:j-1))then
                call unite(uf,now,to)
            endif
            to = w*i+j+1
            if(j<w .and.s(i)(j:j)/=s(i)(j+1:j+1))then
                call unite(uf,now,to)
            endif
        enddo
    enddo

    do i = 1,h
        do j = 1,w
            to = root(uf,i*w+j)
            if(did(to) == 0 )then
                did(to) = 1
                ans = ans + uf%g1(to)*uf%g2(to)
            endif
        enddo
    enddo
    write(*,'(I0)')ans
    stop 
contains


end program atcoder
