io = STDIN
H,W=io.gets.split.map(&:to_i)
S=H.times.map{" #{io.gets.chomp} "}
S.unshift " "*(H+2)
S << " "*(H+2)
HASH={}
def reverse(ch)
  (ch=="#") ? "." : "#"
end
def search(i,j,orgi,orgj,bw,hist)
  if bw=="."  && !HASH[[orgi,orgj,i,j]]
    HASH[[orgi,orgj,i,j]]=true
  end
  [[0,1],[1,0],[0,-1],[-1,0]].each do |x,y|
    if S[i+x][j+y]==reverse(bw) && !hist.include?([i+x,j+y])
        search(i+x,j+y,orgi,orgj,reverse(bw),hist+[[i+x,j+y]])
    else
    end
  end
end
(1..H).each do |i|
  (1..W).each do |j|
    search(i,j,i,j,"#",[[i,j]]) if S[i][j]=="#"
  end
end
puts HASH.size
