H,W=gets.split.map(&:to_i)
$array = Array.new(H).map{Array.new(W).map{Array.new(2,0)}}
H.times do |i|
  str = gets.chomp!
  $cnt = 0
  str.chars {|ch|
    if ch =="#"
      $array[i][$cnt] = [0,0]
    elsif ch =="."
      $array[i][$cnt] = [1,0]
    end
    $cnt += 1
  }
end
$cnt = 0
def explode(color,column,row)
  if row+1<W && $array[column][row+1][0] == (color+1)%2 && $array[column][row+1][1] == 0
    if color == 0
      $cnt += 1
    end
    $array[column][row+1][1] = 1
    explode((color+1)%2,column,row+1)
  end
  if row-1>-1 && $array[column][row-1][0] == (color+1)%2 && $array[column][row-1][1] == 0
    if color == 0
      $cnt += 1
    end
    $array[column][row-1][1] = 1
    explode((color+1)%2,column,row-1)
  end
  if column+1<H && $array[column+1][row][0] == (color+1)%2 && $array[column+1][row][1] == 0
    if color == 0
      $cnt += 1
    end
    $array[column+1][row][1] = 1
    explode((color+1)%2,column+1,row)
  end
  if column-1>-1 && $array[column-1][row][0] == (color+1)%2 && $array[column-1][row][1] == 0
    if color == 0
      $cnt += 1
    end
    $array[column-1][row][1] = 1
    explode((color+1)%2,column-1,row)
  end
end
#puts $array[0][2][0]
$array.each_with_index { |row,i|
  row.each_with_index { |fac,j|
    if fac[0] == 0
      fac[1] = 1
#      puts "#{i} is i. #{j} is j"
      explode(0,i,j)
      $array.each {|a|
        a.each {|b|
          b[1] = 0
        }
      }
    end
  }
}
puts $cnt
