import scala.collection.mutable

object PropertyDistribution extends App {

  val scanner = new java.util.Scanner(System.in)

  val i,j = scanner.nextInt()
  val map = Array.fill(i)(scanner.next()).map(_.toCharArray)

  scanner.nextLine()


  val visited = mutable.Set[(Int, Int)]()

  val direction = List((0,1),(1,0), (0,-1),(-1,0))

  var answer = 0

  def checkNext(now: (Int, Int)): Unit = {
    if (visited.contains(now)) return

    visited += now

    val (x, y) = now

    for {
      (dx, dy) <- direction
    } {
      if (((0 until i) contains (x + dx) )&& ((0 until j) contains (y + dy))&& map(x + dx)(y + dy) == map(x)(y)) {
        checkNext((x + dx, y + dy))
      }

    }
  }

  def traverse = for (i <- 0 until i ; j <- 0 until j){
    if(! visited.contains((i, j))){
      checkNext(i, j)
      answer += 1
    }

  }

  traverse

  println(answer)


}