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