h, w = gets.split.map(&:to_i)
total = h * w
black = 0
a = []
a[0] = ("-1 " * (w+2)).split.map(&:to_i)
for hh in 1..h do
  tmp = gets.chomp
  a[hh] = []
  a[hh][0] = -1
  for ww in 1..w do
    if tmp[ww-1] == "#"
      a[hh][ww] = 0
      black += 1
    else
      a[hh][ww] = total
    end
  end
  a[hh][w+1] = -1
end
a[h+1] = ("-1 " * (w+2)).split.map(&:to_i)

step = 0
while black < total do
  step += 1
  for hh in 1..h do
    for ww in 1..w do
      if a[hh][ww] == (step - 1)
        if a[hh-1][ww] == total
          a[hh-1][ww] = step
          black += 1
        end
        if a[hh+1][ww] == total
          a[hh+1][ww] = step
          black += 1
        end
        if a[hh][ww-1] == total
          a[hh][ww-1] = step
          black += 1
        end
        if a[hh][ww+1] == total
          a[hh][ww+1] = step
          black += 1
        end
      end
    end
  end
end

puts step
