h,w = gets.split.map(&:to_i)
a = []
h.times do
  a.push gets.chomp.split('')
end
black = []
white = []
h.times do |i|
  a[i].each_index do |j|
    case a[i][j]
    when '#'
      black.push [i,j]
    when '.'
      white.push [i,j]
    end
  end
end
d = Array.new(h) { Array.new(w) { 10**6 } }
white.each do |e|
  x = e.first
  y = e.last
  black.each do |b|
    xb = b.first
    yb = b.last
    dist = (x-xb).abs + (y-yb).abs
    d[x][y] = dist if d[x][y] > dist
  end
end
max = 0
white.each do |e|
  x = e.first
  y = e.last
  max = d[x][y] if max < d[x][y]
end
puts max
