$h, $w = gets.chomp.split.map(&:to_i)

$a = []
$h.times do |i|
  $a[i] = gets.chomp.split('').map{|c| c == '#' ? 0 : 9999 }
end

$q = []

def bfs(i, j)
  if i != 0
    if $a[i-1][j] > $a[i][j] + 1
      $a[i-1][j] = $a[i][j] + 1
      $q.push([i-1, j])
    end
  end

  if j != 0
    if $a[i][j-1] > $a[i][j] + 1
      $a[i][j-1] = $a[i][j] + 1
      $q.push([i, j-1])
    end
  end

  if i != $h-1
    if $a[i+1][j] > $a[i][j] + 1
      $a[i+1][j] = $a[i][j] + 1
      $q.push([i+1, j])
    end
  end

  if j != $w-1
    if $a[i][j+1] > $a[i][j] + 1
      $a[i][j+1] = $a[i][j] + 1
      $q.push([i, j+1])
    end
  end
end

$h.times do |i|
  $w.times do |j|
    $q.push([i, j]) if $a[i][j] == 0
  end
end

while !$q.empty?
  i, j = $q.shift
  bfs(i, j)
end

puts($a.map(&:max).max)