open System

// prelude
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let (H,W) = readInts() |> pair
let S = 
  let S = Array2D.zeroCreate H W
  for i in 0..(H-1) do
    readStr().ToCharArray() |> Array.iteri (fun j c -> S.[i,j] <- c='#')
  S

let result =
  let seen = Array2D.create H W false
  let group = Array2D.create H W None
  let r = Array2D.create H W 0
  let dfs (py,px) =
    let rec go (y,x) =
      seen.[y,x]<-true
      let v=S.[y,x]
      if v then do group.[y,x] <- Some (py,px)
      [(y-1,x); (y+1,x); (y,x-1); (y,x+1)]
      |> List.toSeq
      |> Seq.filter (fun (y,x) -> 0<=y&&y<H&&0<=x&&x<W)
      |> Seq.filter (fun (y,x) -> (not seen.[y,x]) && (S.[y,x]<>v))
      |> Seq.sumBy (fun (y,x) ->
        go (y,x)
        + if v then 1 else 0
      )
    r.[py,px]<-go (py,px)
  S |> Array2D.iteri (fun i j x -> if x && not seen.[i,j] then do dfs (i,j))

  seq {
    for i in 0..(H-1) do
      for j in 0..(W-1) do
        yield
          match group.[i,j] with
          | Some (y,x) -> r.[y,x]
          | None -> 0
  }
  |> Seq.sum
printfn "%d" result
