Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import collections

def main():
    N, M = list(map(int, input().split()))

    for i in range(M):
        L, R = list(map(int, input().split()))

        if i == 0:
            ori_arr = set(range(L, R+1))
            continue

        next_arr = set(range(L, R+1))

        ori_arr = set(ori_arr & next_arr)


    print(len(ori_arr))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
import collections

def main():
    N, M = list(map(int, input().split()))

    L = [0] * M
    R = [0] * M
    for i in range(M):
        L[i], R[i] = list(map(int, input().split()))

    ans = (int(min(R)) - int(max(L)) + 1)
    if ans < 0:
        print('0')
    else:
        print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import collections

def main():
    N, M = list(map(int, input().split()))

    for i in range(M):
        L, R = list(map(int, input().split()))

        if i == 0:
            ori_arr = set(range(L, R+1))
            continue

        next_arr = set(range(L, R+1))

        ori_arr = set(ori_arr & next_arr)


    print(len(ori_arr))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
import collections

def main():
    N, M = list(map(int, input().split()))

    L = [0] * M
    R = [0] * M
    for i in range(M):
        L[i], R[i] = list(map(int, input().split()))

    ans = (int(min(R)) - int(max(L)) + 1)
    if ans < 0:
        print('0')
    else:
        print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import collections

def main():
    N, M = list(map(int, input().split()))

    arr = []
    for x in range(M):
        L, R = list(map(int, input().split()))

        for y in range(L, R+1):
            arr.append(y)

    arrcnt = collections.Counter(arr).values()
    print(sum(i == M for i in arrcnt))


if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
import collections

def main():
    N, M = list(map(int, input().split()))

    L = [0] * M
    R = [0] * M
    for i in range(M):
        L[i], R[i] = list(map(int, input().split()))

    ans = (int(min(R)) - int(max(L)) + 1)
    if ans < 0:
        print('0')
    else:
        print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections

def main():
    N, M = list(map(int, input().split()))

    arr = []
    for x in range(M):
        L, R = list(map(int, input().split()))

        for y in range(L, R+1):
            arr.append(y)

    arrcnt = collections.Counter(arr).values()
    print(sum(i == M for i in arrcnt))


if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
import collections

def main():
    N, M = list(map(int, input().split()))

    L = [0] * M
    R = [0] * M
    for i in range(M):
        L[i], R[i] = list(map(int, input().split()))

    ans = (int(min(R)) - int(max(L)) + 1)
    if ans < 0:
        print('0')
    else:
        print(ans)

if __name__ == '__main__':
    main()