h, w = gets.split.map(&:to_i)
grid = []
aryB = []
cntB = 0

h.times do |i|
  tmp = gets.chomp.chars
  w.times do |j|
    if tmp[j] == '#'
      aryB << [i, j]
      cntB += 1
    end
  end
  grid << tmp
end

#p grid, aryB, cntB

maxA = 0
aryC00 = []
aryCh0 = []
aryC0w = []
aryChw = []

for i in 0 .. cntB - 1
  
  for j in i + 1 .. cntB - 1
    tmpA = (aryB[i][0] - aryB[j][0]).abs + (aryB[i][1] - aryB[j][1]).abs - 2
    if maxA < tmpA
      maxA = tmpA
    end
  end
  
  tmpi = aryB[i][0]
  tmpj = aryB[i][1]
  
  aryC00 << tmpi + tmpj
  aryCh0 << h - tmpi - 1 + tmpj
  aryC0w << tmpi + w - tmpj - 1
  aryChw << h - tmpi + w - tmpj - 2
end

puts [(maxA / 2.0).ceil, aryC00.min, aryCh0.min, aryC0w.min, aryChw.min].max