Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    (n, m) = list(map(int, input().split(" ")))
    results = [0] * n
    for i in range(m):
        o = list(map(int, input().split(" ")))
        if i == 0:
            results[o[0]:o[1]+1] = [1] * (o[1]+1-o[0])
            continue
        for j in range(n):
            if not results[j]:
                continue
            if not (o[0] <= j and j <= o[1]):
                results[j] = 0
                if o[1] < j:
                    break
            if results.count(1) == 0:
                print(0)
                return

    print(results.count(1))


if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    (n, m) = list(map(int, input().split(" ")))
    
    for i in range(m):
        o = list(map(int, input().split(" ")))
        if i == 0:
            lmax = o[0]
            rmin = o[1]
        else:
            lmax = max(lmax, o[0])
            rmin = min(rmin, o[1])

    print(rmin-lmax+1 if lmax <= rmin else 0)


if '__main__' == __name__:
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    (n, m) = list(map(int, input().split(" ")))
    intersects = set()
    for i in range(m):
        o = list(map(int, input().split(" ")))
        if i == 0:
            intersects = set(range(o[0], o[1]+1))
        else:
            intersects = intersects & set(range(o[0], o[1]+1))
            if len(intersects) == 0:
                break

    print(len(intersects))


if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    (n, m) = list(map(int, input().split(" ")))
    
    for i in range(m):
        o = list(map(int, input().split(" ")))
        if i == 0:
            lmax = o[0]
            rmin = o[1]
        else:
            lmax = max(lmax, o[0])
            rmin = min(rmin, o[1])

    print(rmin-lmax+1 if lmax <= rmin else 0)


if '__main__' == __name__:
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    (n, m) = list(map(int, input().split(" ")))
    intersects = set()
    for i in range(m):
        o = list(map(int, input().split(" ")))
        if i == 0:
            intersects = set(range(o[0], o[1]+1))
        else:
            intersects = intersects & set(range(o[0], o[1]+1))

    print(len(intersects))


if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    (n, m) = list(map(int, input().split(" ")))
    
    for i in range(m):
        o = list(map(int, input().split(" ")))
        if i == 0:
            lmax = o[0]
            rmin = o[1]
        else:
            lmax = max(lmax, o[0])
            rmin = min(rmin, o[1])

    print(rmin-lmax+1 if lmax <= rmin else 0)


if '__main__' == __name__:
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    (n, m) = list(map(int, input().split(" ")))
    intersects = set()
    for i in range(m):
        o = list(map(int, input().split(" ")))
        l = []
        for k in range(o[0], o[1]+1):
            l.append(k)
        if i == 0:
            intersects = set(l)
        else:
            intersects = intersects & set(l)

    print(len(intersects))


if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    (n, m) = list(map(int, input().split(" ")))
    
    for i in range(m):
        o = list(map(int, input().split(" ")))
        if i == 0:
            lmax = o[0]
            rmin = o[1]
        else:
            lmax = max(lmax, o[0])
            rmin = min(rmin, o[1])

    print(rmin-lmax+1 if lmax <= rmin else 0)


if '__main__' == __name__:
    resolve()