# Definition for an interval.
# class Interval:
#     def __init__(self, s=0, e=0):
#         self.start = s
#         self.end = e

class Solution:
    def eraseOverlapIntervals(self, intervals):
        """
        :type intervals: List[Interval]
        :rtype: int
        """
        n=len(intervals)
        if n<=1:
            return 0
        intervals.sort(key=lambda x:(x.end,x.start))
        end,count=intervals[0].end,0
        for i in range(1,n,1):
            if intervals[i].start<end:
                count+=1
                continue
            else:
                end=intervals[i].end
        return count