def find_longest_ranges(range, howmany):
    """
    from range of count_ranges, return the 'howmany' longest ranges

    :param range: list of ranges [end, length]
    :param howmany: int, number of ranges to return
    :return: list of 'howmany' [end, length] items, sorted
    """
    range.sort(key=lambda x: x[1])  # sort by length
    if howmany > 1:
        range = range[-howmany:]  # get last few
        range.sort(key=lambda x: x[0])  # sorted by starttime
        return range
    else:
        return range[-1]