require 'set'
require 'mathn'

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

h.times do
	f.unshift gets.chomp.split("")
end
f.reverse.each{|x| puts x.join}

as = Set.new
lines = []

(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
				lines << [[x - len, y], [x, y]]
				as << y / x
				as << y / (x - len) unless x - len == 0
			end
			len = 0
		end
		x += 1

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

(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
				lines << [[x, y - len], [x, y]]
				as << y / x unless x == 0
				as << (y - len) / x unless x == 0
			end
			len = 0
		end
		y += 1

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

as.delete(0)

p as.map {|a|
	a -= 1 / 1000000	
	#y - a x = 0
	k = 0
	lines.each do |(x1, y1), (x2, y2)|
		k += 1 if (y1 - a * x1) * (y2 - a * x2) <= 0
	end
	k -= 1 if f[0][0] == ?#
	k / 2 + 1
}.max