$h, $w = gets.split.map(&:to_i)
$c = []
$d = []
$h.times do
  $c.push gets.chomp.split('')
  $d.push []
end

q = []

0.upto($h - 1) do |i|
  0.upto($w - 1) do |j|
    if $c[i][j] == '#'
      q.push([i, j])
      $d[i][j] = 0
    else
      $d[i][j] = -1
    end
  end
end

p = q.shift
max = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
loop do
  xx = p[0]
  yy = p[1]
  0.upto(3) do |i|
    x = xx + dx[i]
    y = yy + dy[i]
    next if x < 0 || x > $h - 1 || y < 0 || $w - 1 < y || $d[x][y] >= 0

    if $c[x][y] == '.'
      q.push([x, y])
      count = $d[xx][yy] + 1
      max = count if max < count
      $d[x][y] = count
    end
  end
  break if q.empty?

  p = q.shift
end
puts max
