import heapq

class Solution:
    def __init__(self, value, list_num, index):
        self.value = value
        self.list_num = list_num
        self.index = index

    def smallestRange(self, nums):
        if not nums or any(len(arr) == 0 for arr in nums):
            return []

        heap = []
        current_max = float('-inf')

        for i, arr in enumerate(nums):
            node = Solution(arr[0], i, 0)
            heapq.heappush(heap, (node.value, node.list_num, node.index))
            current_max = max(current_max, arr[0])

        best_start, best_end = heap[0][0], current_max

        while len(heap) == len(nums):
            min_val, list_num, idx = heapq.heappop(heap)

            if current_max - min_val < best_end - best_start or (
                current_max - min_val == best_end - best_start and min_val < best_start
            ):
                best_start, best_end = min_val, current_max

            if idx + 1 < len(nums[list_num]):
                next_val = nums[list_num][idx + 1]
                heapq.heappush(heap, (next_val, list_num, idx + 1))
                if next_val > current_max:
                    current_max = next_val
            else:
                break

        return [best_start, best_end]