MOVES = [[1,0], [0,1], [-1,0], [0,-1]]

H, W = gets.split.map(&:to_i)
grid = Array.new(H) { gets.chomp }

black_cells = []
dist = {}
H.times do |h|
  W.times do |w|
    if grid[h][w] == '#'
      black_cells << [h,w]
      dist[[h,w]] = 0
    end
  end
end

def area? p
  (0..H-1).include?(p[0]) && (0..W-1).include?(p[1])
end

def bfs black_cells, dist
  d = 0
  until black_cells.empty?
    now = black_cells.shift
    d = dist[now]
    MOVES.each do |dh, dw|
      new = now[0] + dh, now[1] + dw
      if area? new
        if dist[new].nil?
          dist[new] = d + 1
          black_cells << new
        end
      end
    end
  end
  d
end

d = bfs black_cells, dist
puts d