require 'set'

class Array
	def accum
		inject([0]){|a, x| a + [a[-1] + x]}
	end

	def accum!
		(1..size-1).each{|i|
			self[i] += self[i-1]
		}
		self.unshift(0)
	end

	def accum_2d
		ac = map{|r| r.accum}
		(1..size-1).each{|i|
			(1..ac[0].size-1).each{|j|
				ac[i][j] += ac[i-1][j]
			}
		}
		ac.unshift([0] * ac[0].size)
		ac
	end

	def accum_2d!
		each{|r| r.accum!}
		(1..size-1).each{|i|
			(1..self[0].size-1).each{|j|
				self[i][j] += self[i-1][j]
			}
		}
		unshift([0] * self[0].size)
	end
		
	def bsearch_first_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_first_index(l, c-1, &pred) || c
		else
			bsearch_first_index(c+1, r, &pred)
		end
	end

	def bsearch_first_item(l = 0, r = size - 1, &pred)
		i = bsearch_first_index(l, r, &pred)
		i ? self[i] : nil
	end

	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end

	def bsearch_last_item(l = 0, r = size - 1, &pred)
		i = bsearch_last_index(l, r, &pred)
		i ? self[i] : nil
	end
end

def compress(used_x)
	x_map = {}
	used_x.to_a.uniq.sort.each_with_index{|x, i| x_map[x] = i}
	x_map
end

h, w = gets.split.map &:to_i
f = []

h.times do
	f.unshift gets.chomp.split("")
end

as = Set.new

h_lines = (0..h).map { [] }
(0..h).each do |y|
	x = 0
	len = 0
	loop do
		if (y != 0 && f[y-1][x] == ?#) ^ (y != h && f[y][x] == ?#)
			len += 1
		else
			if len > 0
				h_lines[y] << [x - len, x]
				as << Rational(y, x)
				as << Rational(y, x - len) unless x - len == 0
			end
			len = 0
		end
		x += 1

		if x == w
			if len > 0
				h_lines[y] << [x - len, x]
				as << Rational(y, x)
				as << Rational(y, x - len) unless x - len == 0
			end
			break
		end
	end
end

v_lines = (0..w).map { [] }
(0..w).each do |x|
	y = 0
	len = 0
	loop do
		if (x != 0 && f[y][x-1] == ?#) ^ (x != w && f[y][x] == ?#)
			len += 1
		else
			if len > 0
				v_lines[x] << [y - len, y]
				as << Rational(y, x) unless x == 0
				as << Rational(y - len, x) unless x == 0
			end
			len = 0
		end
		y += 1

		if y == h
			if len > 0
				v_lines[x] << [y - len, y]
				as << Rational(y, x) unless x == 0
				as << Rational(y - len, x) unless x == 0
			end
			break
		end
	end
end 

as << Float::INFINITY
a_map = compress(as)

pile = [0] * a_map.size

(1..h).each do |y|
	h_lines[y].each do |x1, x2|
		i = a_map[x1 == 0 ? Float::INFINITY : Rational(y, x1)]
		j = a_map[Rational(y, x2)]
		pile[j] += 1
		pile[i] -= 1
	end
end

(1..w).each do |x|
	v_lines[x].each do |y1, y2|
		i = a_map[Rational(y1, x)]
		j = a_map[Rational(y2, x)]
		pile[i] += 1
		pile[j] -= 1
	end
end

k = pile.accum.max
k += 1 if f[0][0] == ?#
p k / 2 + 1