let (h, w) = Scanf.sscanf (read_line ()) "%d %d" @@ fun h w -> (h, w)
let s = Array.init h @@ fun _ -> read_line ()

let t = Array.init h @@ fun _ -> Array.make w 0

let f x y ch = if x < 0 || (h - 1) < x || y < 0 || (w - 1) < y then false else t.(x).(y) = 0 && s.(x).[y] <> ch

let rec g x y i =
  t.(x).(y) <- i;
  List.iter 
    (fun (a, b) -> if f a b s.(x).[y] then g a b i) 
    [(x - 1, y); (x + 1, y); (x, y - 1); (x, y + 1)]

let () =
  let v = ref 1 in
  for i = 0 to (h - 1) do
    for j = 0 to (w - 1) do
      if t.(i).(j) = 0 then begin
        g i j !v;
        v := !v + 1
      end
    done
  done;
  let arr = Array.make !v (0, 0) in
  for i = 0 to (h - 1) do
    for j = 0 to (w - 1) do
      let n = t.(i).(j) in
      let (w, b) = arr.(n - 1) in
      arr.(n - 1) <- if s.(i).[j] = '.' then (w + 1, b) else (w, b + 1)
    done
  done;
  print_int @@ Array.fold_left (fun sum (w, b) -> sum + w * b) 0 arr;
  print_newline ()
