def upd(table, queue, n, i, j, h, w)
  return if i < 0 || j < 0 || i >= h || j >= w

  queue << [n + 1, i, j] if table[i][j] == "."
end

def main
  h, w = gets.chomp.split(' ').map(&:to_i)
  table = []
  h.times {
    table << gets.chomp.chars.to_a
  }

  queue = []
  cnt = 0

  table.each_with_index {|row, i|
    row.each_with_index {|c, j|
      if c == "#"
        queue << [0, i, j]
        table[i][j] = "." # reset flag...
        cnt += 0
      end    
    }
  }

  last_n = -1
  
  loop {
    break if cnt >= h * w

    n, i, j = queue.shift

    if table[i][j] == "."
      cnt += 1
      last_n = n

      table[i][j] = "#"

      upd(table, queue, n, i - 1, j, h, w)
      upd(table, queue, n, i + 1, j, h, w)
      upd(table, queue, n, i, j - 1, h, w)
      upd(table, queue, n, i, j + 1, h, w)
    end
  }
  puts last_n
end

main
  