Buggy python submission (verdict: Time Limit Exceeded):

N,M=map(int,input().split())

result=0
LR=[]
for i in range(M):
        LR.append(input().split())


for i in range(N+1):#0からNまで
    counter=0
    flag=False
    if flag:
        break
    for j in LR:

        L=int(j[0])
        R=int(j[1])
        if i<L or R<i:
            flag=True
            break
        if L<=i and i<=R:
            counter+=1

    if counter==M:
        result+=1
print(result)


Fixed submission:

N,M=map(int,input().split())#ID,ゲート


LR=[]
for i in range(M):
        LR.append(input().split())


numbers=[]
for i in range(N+1):
    numbers.append(i)




Lmax=1
Rmax=100000
for j in LR:

    L=int(j[0])
    R=int(j[1])

    if Lmax<L:
        Lmax=L
    if Rmax>R:
        Rmax=R
result=0

for i in numbers:

    if i>=Lmax:

        if i<=Rmax:
            result+=1



print(result)

Buggy python submission (verdict: Time Limit Exceeded):

N,M=map(int,input().split())

result=0
LR=[]
for i in range(M):
        LR.append(input().split())


for i in range(N+1):#0からNまで
    counter=0
    flag=False
    for j in LR:
        if flag:
            break
        L=int(j[0])
        R=int(j[1])
        if i<L or R<i:
            flag=True
            break
        if L<=i and i<=R:
            counter+=1

    if counter==M:
        result+=1
print(result)


Fixed submission:

N,M=map(int,input().split())#ID,ゲート


LR=[]
for i in range(M):
        LR.append(input().split())


numbers=[]
for i in range(N+1):
    numbers.append(i)




Lmax=1
Rmax=100000
for j in LR:

    L=int(j[0])
    R=int(j[1])

    if Lmax<L:
        Lmax=L
    if Rmax>R:
        Rmax=R
result=0

for i in numbers:

    if i>=Lmax:

        if i<=Rmax:
            result+=1



print(result)

Buggy python submission (verdict: Time Limit Exceeded):

N,M=map(int,input().split())

result=0
LR=[]
for i in range(M):
        LR.append(input().split())

for i in range(N+1):#0からNまで
    counter=0
    for j in LR:#['1','1']
        #print(j)

        L=int(j[0])
        R=int(j[1])
        if i<L or R<i:
            break
        if L<=i and i<=R:
            counter+=1

    if counter==M:
        result+=1
print(result)


Fixed submission:

N,M=map(int,input().split())#ID,ゲート


LR=[]
for i in range(M):
        LR.append(input().split())


numbers=[]
for i in range(N+1):
    numbers.append(i)




Lmax=1
Rmax=100000
for j in LR:

    L=int(j[0])
    R=int(j[1])

    if Lmax<L:
        Lmax=L
    if Rmax>R:
        Rmax=R
result=0

for i in numbers:

    if i>=Lmax:

        if i<=Rmax:
            result+=1



print(result)

Buggy python submission (verdict: Time Limit Exceeded):

N,M=map(int,input().split())

result=0
LR=[]
for i in range(M):
        LR.append(input().split())

for i in range(N+1):#0からNまで
    counter=0
    for j in LR:#['1','1']
        #print(j)

        L=int(j[0])
        R=int(j[1])

        if L<=i and i<=R:
            counter+=1
        if i<L or R<i:
            break
    if counter==M:
        result+=1
print(result)


Fixed submission:

N,M=map(int,input().split())#ID,ゲート


LR=[]
for i in range(M):
        LR.append(input().split())


numbers=[]
for i in range(N+1):
    numbers.append(i)




Lmax=1
Rmax=100000
for j in LR:

    L=int(j[0])
    R=int(j[1])

    if Lmax<L:
        Lmax=L
    if Rmax>R:
        Rmax=R
result=0

for i in numbers:

    if i>=Lmax:

        if i<=Rmax:
            result+=1



print(result)

Buggy python submission (verdict: Time Limit Exceeded):


N,M=map(int,input().split())

result=0
LR=[]
for i in range(M):
        LR.append(input().split())



for i in range(N+1):#0からNまで
    counter=0
    for j in LR:#['1','1']
        #print(j)

        L=int(j[0])
        R=int(j[1])

        if L<=i and i<=R:
            counter+=1
    if counter==M:
        result+=1
print(result)


Fixed submission:

N,M=map(int,input().split())#ID,ゲート


LR=[]
for i in range(M):
        LR.append(input().split())


numbers=[]
for i in range(N+1):
    numbers.append(i)




Lmax=1
Rmax=100000
for j in LR:

    L=int(j[0])
    R=int(j[1])

    if Lmax<L:
        Lmax=L
    if Rmax>R:
        Rmax=R
result=0

for i in numbers:

    if i>=Lmax:

        if i<=Rmax:
            result+=1



print(result)