Sort the intervals