h,w = gets.split.map(&:to_i)
s = h.times.map{gets.chomp.chars.map{|c|c==?#}}

#p s

def saiki(h,w,s,i,j,used)
  return 0 if used[i][j]
  used[i][j] = true
  res = 0
  res += saiki(h,w,s,i-1,j,used) if 0<i   && s[i][j]!=s[i-1][j]
  res += saiki(h,w,s,i+1,j,used) if i<h-1 && s[i][j]!=s[i+1][j]
  res += saiki(h,w,s,i,j-1,used) if 0<j   && s[i][j]!=s[i][j-1]
  res += saiki(h,w,s,i,j+1,used) if j<w-1 && s[i][j]!=s[i][j+1]
  res += (s[i][j] ? 0:1)
  return res
end

memo = h.times.map{Array.new(w, -1)}

ans = 0
h.times{|i|
  w.times{|j|
    used = h.times.map{Array.new(w, false)}
    ans += saiki(h,w,s,i,j,used) if s[i][j]
  }
}

p ans
