import scala.io.StdIn
import scala.annotation.tailrec
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
    } {
        (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.root(flat(i, j)) != uft.root(flat(y, x))) {
            uft.unite(flat(i,j), flat(y,x))
          }
        })
    }

    def f(fy:Int, fx:Int):Int = {
      var cnt = 0
      val root = uft.root(flat(fy, fx))
      val set = HashSet.empty[(Int,Int)]

      def dfs(ey:Int, ex:Int):Unit = {
        if(set.contains(ey,ex) || uft.root(flat(ey, ex)) != root) return
        else {
          if(!table(ey)(ex)) cnt += 1
          set.add(ey,ex)
          (0 until 4).foreach(i => {
            val y = ey + dy(i)
            val x = ex + dx(i)
            if(0 <= y && y < h && 0 <= x && x < w &&
                table(ey)(ex) != table(y)(x)) {
              dfs(y, x)
            }
          })
        }
      }
      dfs(fy, fx)
      cnt
    }
    val res = for {
      i <- 0 until h
      j <- 0 until w
      if table(i)(j)
    } yield f(i, j)

    res.sum
  }

  println(ans)

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

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

    def same(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
      else {
        par(ry) = rx
        if(rank(rx) == rank(ry)) rank(rx) += 1
      }
    }
  }
}