h,w=gets.split.map(&:to_i)
s=[]
h.times do
  s << gets.chomp.chars
end
a=0
h.times do |i|
  w.times do |j|
    if s[i][j]==nil
      next
    elsif s[i][j]=="."
      f="#"
      ha=Hash.new(0)
      ha["."]=1
    else
      f="."
      ha=Hash.new(0)
      ha["#"]=1
    end
    s[i][j]=nil
    q=[[i,j]]
    while q!=[]
      z=[]
      q.each do |qi,qj|
        if qi>0&&s[qi-1][qj]==f
          s[qi-1][qj]=nil
          z << [qi-1,qj]
          ha[f]+=1
        end
        if qj>0&&s[qi][qj-1]==f
          s[qi][qj-1]=nil
          z << [qi,qj-1]
          ha[f]+=1
        end
        if qi<h-1&&s[qi+1][qj]==f
          s[qi+1][qj]=nil
          z << [qi+1,qj]
          ha[f]+=1
        end
        if qj<w-1&&s[qi][qj+1]==f
          s[qi][qj+1]=nil
          z << [qi,qj+1]
          ha[f]+=1
        end
      end
      if f=="."
        f="#"
      else
        f="."
      end
      q=z.dup
    end
    a+=ha["."]*ha["#"]
  end
end
puts a
