attrs = Array.new
while line = $stdin.gets
  attrs << line.chomp.split
end

matrix = Array.new(attrs[0][0].to_i) { Array.new(attrs[0][1].to_i)}

for row in 0..matrix.size-1
    for column in 0..matrix[0].size-1
        matrix[row][column] = attrs[row+1][0][column]
    end
end

def create_dark(matrix, count)
    queue = []
    for row in 0..matrix.size-1
        for col in 0..matrix[0].size-1
            next if matrix[row][col] == '.'
            queue << [row, col] if remaining?(matrix, row, col)
        end
    end

    return count if queue.empty?

    while !queue.empty?
        row, col = queue.pop
        if row > 0
            matrix[row-1][col] = '#'
        end

        if row < matrix.size-1
            matrix[row+1][col] = '#'
        end

        if col > 0
            matrix[row][col-1] = '#'
        end

        if col < matrix[0].size-1
            matrix[row][col+1] = '#'
        end
    end

    count += 1

    create_dark(matrix, count)
end

def remaining?(matrix, row, col)
    (row > 0 && matrix[row-1][col] == '.') || (row < matrix.size-1 && matrix[row+1][col] == '.') || (col > 0 && matrix[row][col-1] == '.') || (col < matrix[0].size-1 && matrix[row][col+1] == '.')
end

p create_dark(matrix, 0)

=begin
######
#.#.##
#.####
#.#.##
######
######
=end