import scala.collection.mutable

object Main {

  def main(arg: Array[String]): Unit = {

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

    var i, j = scanner.nextInt()
    while (i != 0 && j != 0) {
      val map = Array.fill(i)(scanner.next()).map(_.toCharArray)

      val hoge = fordataset(i, j, map)

      println(hoge)

      i = scanner.nextInt()
      j = scanner.nextInt()
    }
  }

  def fordataset(i: Int, j: Int, map: Array[Array[Char]]): Int = {
    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

    answer
  }


}