import scala.io.StdIn
import scala.collection.mutable.HashSet

object Main extends App {
  val Array(h, w) = StdIn.readLine.split(" ").map(_.toInt)
  val table = Iterator.continually(StdIn.readLine)
    .take(h)
    .map(_.map(_ == '#').toArray)
    .toArray

  @inline
  def flat(i:Int, j:Int):Int = i * w + j

  val ans = {
    val dx = Array(0, 1, 0, -1)
    val dy = Array(-1, 0, 1, 0)
    val uft = new UnionFindTree(flat(h, w))

    for{
      i <- 0 until h
      j <- 0 until w
    } {
        val ij = flat(i,j)
        (0 until 4).foreach(k => {
          val y = i + dy(k)
          val x = j + dx(k)
          if(0 <= y && y < h && 0 <= x && x < w &&
              table(i)(j) != table(y)(x) ) {
            uft.unite(ij, flat(y,x))
          }
        })
    }
    uft.set./:(0L)((acc,e) => {
      acc + uft.black(e).toLong * uft.white(e).toLong
    })
  }

  println(ans)

  class UnionFindTree(n:Int) {
    private val par  = Array.range(0, n)
    private val rank = Array.fill(n)(1)

    val set = HashSet.empty[Int]
    val black = Array.ofDim[Int](n)
    val white = Array.ofDim[Int](n)
    for {
      i <- 0 until h
      j <- 0 until w
    } {
      if(table(i)(j)) black(flat(i,j)) = 1 else white(flat(i,j)) = 1
    }

    def root(x:Int):Int = {
      if(par(x) == x) x
      else { par(x) = root(par(x)); par(x) }
    }

    def isSame(x:Int, y:Int):Boolean = root(x) == root(y)

    def unite(x:Int, y:Int):Unit = {
      val rx = root(x)
      val ry = root(y)
      if(rx == ry) return

      if(rank(rx) < rank(ry)) {
        par(rx) = ry

        set += ry
        if(set.contains(rx)) set - rx

        black(ry) += black(rx)
        white(ry) += white(rx)
        black(rx) = 0
        white(rx) = 0
      }
      else {
        par(ry) = rx
        if(rank(rx) == rank(ry)) rank(rx) += 1

        set += rx
        if(set.contains(ry)) set - ry

        black(rx) += black(ry)
        white(rx) += white(ry)
        black(ry) = 0
        white(ry) = 0
      }
    }
  }
}