h, w = gets.split.map(&:to_i)
total = h * w
black = []
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[0].push([hh, ww])
    else
      a[hh][ww] = total
    end
  end
  a[hh][w+1] = -1
end
a[h+1] = ("-1 " * (w+2)).split.map(&:to_i)
cnt = black[0].size

step = 0
while cnt < total do
  step += 1
  black[step] = []
  black[step-1].each { |hh, ww|
    if a[hh-1][ww] == total
      a[hh-1][ww] = step
      black[step].push([hh-1, ww])
    end
    if a[hh+1][ww] == total
      a[hh+1][ww] = step
      black[step].push([hh+1, ww])
    end
    if a[hh][ww-1] == total
      a[hh][ww-1] = step
      black[step].push([hh, ww-1])
    end
    if a[hh][ww+1] == total
      a[hh][ww+1] = step
      black[step].push([hh, ww+1])
    end
  }
  cnt += black[step].size
end

puts step
