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 r =
  let seen=Array2D.create H W false
  seq {
    for i in 0..(H-1) do
      for j in 0..(W-1) do
        let rec dfs b w y x =
          seen.[y,x]<-true
          let (b',w')=if S.[y,x] then (b+1,w) else (b,w+1)
          [(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']<>S.[y,x])
          |> Seq.fold (fun (b,w) (y,x) -> dfs b w y x) (b',w')
        if S.[i,j]&& not seen.[i,j] then
          yield
            let (b,w)=dfs 0 0 i j in
            b*w
  }
  |> Seq.sum

printfn "%d" r