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

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

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

pile = Hash.new(0)

(1..h).each do |y|
	x = 0
	len = 0
	loop do
		if (f[y-1][x] == ?#) ^ (y != h && f[y][x] == ?#)
			len += 1
		else
			if len > 0
				a1 = Rational(y, x)
				a2 = (x - len == 0 ? Float::INFINITY : Rational(y, x - len))
				pile[a1] += 1
				pile[a2] -= 1
			end
			len = 0
		end
		x += 1

		if x == w
			if len > 0
				a1 = Rational(y, x)
				a2 = (x - len == 0 ? Float::INFINITY : Rational(y, x - len))
				pile[a1] += 1
				pile[a2] -= 1
			end
			break
		end
	end
end

(1..w).each do |x|
	y = 0
	len = 0
	loop do
		if (f[y][x-1] == ?#) ^ (x != w && f[y][x] == ?#)
			len += 1
		else
			if len > 0
				a1 = (x == 0 ? Float::INFINITY : Rational(y, x))
				a2 = (x == 0 ? Float::INFINITY : Rational(y - len, x))
				pile[a2] += 1
				pile[a1] -= 1
			end
			len = 0
		end
		y += 1

		if y == h
			if len > 0
				a1 = (x == 0 ? Float::INFINITY : Rational(y, x))
				a2 = (x == 0 ? Float::INFINITY : Rational(y - len, x))
				pile[a2] += 1
				pile[a1] -= 1
			end
			break
		end
	end
end 

k = pile.sort.map(&:last).accum.max
k += 1 if f[0][0] == ?#
p k / 2 + 1