class Solution:
def videoStitching(self, clips: List[List[int]], time: int) -> int:
clips.sort(key=lambda x: (x[0],-x[1]))
res = 0
i = 0
n = len(clips)
currEnd = 0
nextEnd = 0
while i < n and clips[i][0] <= currEnd:
while i < n and clips[i][0] <= currEnd:
nextEnd = max(nextEnd, clips[i][1])
i += 1
res+=1
currEnd = nextEnd
if currEnd >= time:
return res
return -1