import scala.io.StdIn
import scala.annotation.tailrec

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

  val ans = {
    val dx = Array(0, 1, 0, -1)
    val dy = Array(-1, 0, 1, 0)
    var res = 0;

    def f(y:Int, x:Int):Int = {
      val visit = Array.ofDim[Boolean](h,w)

      def dfs(ey:Int, ex:Int):Unit = {
        if(table(ey)(ex) != table(y)(x) || visit(ey)(ex)) return
        else {
          visit(ey)(ex) = true 
          (0 until 4).foreach(i => {
            val y = ey + dy(i)
            val x = ex + dx(i)
            if(0 <= y && y < h && 0 <= x && x < w) {
              dfs(y, x)
            }
          })
        }
      }

      dfs(y, x)

      val a = for {
        i <- 0 until h
        j <- 0 until w
        if !table(i)(j)
      } { if(visit(i)(j)) res += 1 }
      res
    }

    val ret = for {
      i <- 0 until h
      j <- 0 until w
      if table(i)(j)
    } f(i,j)

    res
  }

  println(ans)
}