h, w = gets.chomp.split.map(&:to_i)
a = []
stack = []
stack[0] = []
h.times do |i|
  a[i] = gets.chomp.split("")
  w.times do |j|
    if a[i][j] == "#"
      stack[0] << [i, j]
    end
  end
end
k = 0
while stack[k] != []
  stack[k+1] = []
  stack[k].each do |i, j|
    if j-1 >= 0 && a[i][j-1] == "."
      a[i][j-1] = k+1
      stack[k+1] << [i, j-1]
    end
    if i-1 >= 0 && a[i-1][j] == "."
      a[i-1][j] = k+1
      stack[k+1] << [i-1, j]
    end
    if j+1 <= w-1 && a[i][j+1] == "."
      a[i][j+1] = k+1
      stack[k+1] << [i, j+1]
    end
    if i+1 <= h-1 && a[i+1][j] == "."
      a[i+1][j] = k+1
      stack[k+1] << [i+1, j]
    end
  end
  k += 1
end
p k-1