ZhenlongDai/ACPR huggingface dataset:
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int,input().split())

l_p = 1
r_p = n

for j in range(m):
  l, r = map(int,input().split())
  if l > l_p:
    l_p = l
  if r < r_p:
    r_p = r

a = r_p - l_p + 1

print(a)

Failing test case input:
10 3
3 2
4 7
6 11

Expected output:
0


Actual output:
-3


Fixed submission (verdict: Accepted):
n, m = map(int,input().split())
 
l_p = 1
r_p = n
 
for j in range(m):
  l, r = map(int,input().split())
  if l > l_p:
    l_p = l
  if r < r_p:
    r_p = r

a = r_p - l_p + 1

if a > 0:
  print(a)
else:
  print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int, input().split())
ns = set(i+1 for i in range(n))
l_min = 0
r_max = n
for i in range(m):
    l, r = map(int, input().split())
    l_min = max(l_min, l)
    r_max = min(r_max, r)
print(r_max - l_min+1)


Failing test case input:
10 3
3 6
5 7
10 8

Expected output:
0


Actual output:
-3


Fixed submission (verdict: Accepted):
n,m = map(int, input().split())
ns = set(i+1 for i in range(n))
l_min = 0
r_max = n
for i in range(m):
    l, r = map(int, input().split())
    l_min = max(l_min, l)
    r_max = min(r_max, r)
print(max(r_max - l_min+1, 0))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
l=[list(map(int, input().split())) for _ in range(M)]

max_L, min_R = (0, N)

for r in l:
    if r[0]>max_L:
        max_L = r[0]
    if r[1]<min_R:
        min_R = r[1]
if min_R > max_L:
    print(min_R - max_L + 1)
else:
    print(0)


Failing test case input:
8 1
6 6
10 3
1 11

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
l=[list(map(int, input().split())) for _ in range(M)]

max_L, min_R = (0, N)

for r in l:
    if r[0]>max_L:
        max_L = r[0]
    if r[1]<min_R:
        min_R = r[1]
if min_R >= max_L:
    print(min_R - max_L + 1)
else:
    print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = list(map(int, input().split()))
maxl = 0
minr = 10000
for i in range(m):
    l, r = list(map(int, input().split()))
    maxl = max(maxl, l)
    minr = min(minr, r)
if minr > maxl:
    print(0)
else:
    print(maxl - minr + 1)

Failing test case input:
4 2
0 6
2 4

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
n, m = list(map(int, input().split()))
maxl = 0
minr = 1000000
for i in range(m):
    l, r = list(map(int, input().split()))
    maxl = max(maxl, l)
    minr = min(minr, r)
if minr < maxl:
    print(0)
else:
    print(minr - maxl + 1)
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())

p = []
q = []

for i in range(m):
    l, r = map(int,input().split())
    p.append(l)
    q.append(r)

p1 = max(p)
q1 = min(q)

if p.__len__() == 1:
    print(q1)
elif q1 >= p1:
    print(q1 - p1 + 1)
else:
    print(0)

Failing test case input:
10 1
3 6
5 7
10 8

Expected output:
4


Actual output:
6


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())

p = []
q = []

for i in range(m):
    l, r = map(int,input().split())
    p.append(l)
    q.append(r)

p1 = max(p)
q1 = min(q)


if q1 >= p1:
    print(q1 - p1 + 1)
else:
    print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = map(lambda x: int(x)-1, input().split())

sum = min(R) - max(L) + 1

print(sum)


Failing test case input:
6 3
3 0
7 7
1 1

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = map(lambda x: int(x)-1, input().split())

sum = 0
maxl = max(L)
minr = min(R)
for id in range(N):
    if maxl <= id and id <= minr:
        sum += 1

print(sum)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = [int(_) for _ in input().split()]

ls = []
rs = []
for i in range(m):
    lr = [int(_) for _ in input().split()]
    ls.append(lr[0])
    rs.append(lr[1])

print(min(min(rs) - max(ls) + 1, 0))


Failing test case input:
8 3
3 0
7 7
1 1

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
n, m = [int(_) for _ in input().split()]

ls = []
rs = []
for i in range(m):
    lr = [int(_) for _ in input().split()]
    ls.append(lr[0])
    rs.append(lr[1])

print(max(min(rs) - max(ls) + 1, 0))

Problem: p03037
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N, M = map(int, input().split())
LL = 0
RR = N
for i in range(M):
    L, R = map(int, input().split())
    if LL < L:
        LL = L
    if RR > R:
        RR = R
print(RR - LL + 1)


Failing test case input:
10 3
3 2
7 15
6 9

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
LL = 0
RR = N
for i in range(M):
    L, R = map(int, input().split())
    if LL < L:
        LL = L
    if RR > R:
        RR = R
print(max(0, RR - LL + 1))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = map(int,input().split())
l = 0
r = N-1
for i in range(M):
    L,R = map(int,input().split())
    l = max(l,L)
    r = min(r,R)
if r-l >= 0:
    print(r-l+1)
else:
    print(0)


Failing test case input:
4 2
1 4
2 4

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
l = 1
r = N
for i in range(M):
    L,R = map(int,input().split())
    l = max(l,L)
    r = min(r,R)
if r-l >= 0:
    print(r-l+1)
else:
    print(0)
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
L, R = 0, float('inf')
for i in range(m):
    l, r = map(int, input().split())
    if l >= L:
        L = l
    if r <= R:
        R = r
print(R-L+1)

Failing test case input:
14 3
3 2
7 7
6 9

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
L, R = 0, n
for i in range(m):
    l, r = map(int, input().split())
    if l > L:
        L = l
    if r < R:
        R = r
if R-L+1 > 0:
    print(R-L+1)
else:
    print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
lLst = [0] * M
rLst = [0] * M
ans = 1
for i in range(M):
    lLst[i], rLst[i] = map(int, input().split())

if lLst[M - 1] < rLst[0]:
    ans += rLst[0] - lLst[M - 1]

print(ans)

Failing test case input:
10 2
3 6
11 0
0 9

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
lLst = [0] * M
rLst = [0] * M
for i in range(M):
    lLst[i], rLst[i] = map(int, input().split())

lLst.sort(reverse=True)
rLst.sort()
if lLst[0] > rLst[0]:
    ans = 0
else:
    ans = rLst[0] - lLst[0] + 1

print(ans)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n,m=map(int,input().split())
L=[]
R=[]
for _ in range(m):
    a,b=map(int,input().split())
    L.append(a)
    R.append(b)
print(min(R)-max(L)+1,0)

Failing test case input:
15 3
3 2
2 7
3 11

Expected output:
0


Actual output:
0 0


Fixed submission (verdict: Accepted):

n,m=map(int,input().split())
L=[]
R=[]
for _ in range(m):
    a,b=map(int,input().split())
    L.append(a)
    R.append(b)
print(max(min(R)-max(L)+1,0))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
L = [list(map(int, input().split())) for i in range(M)]

l0 = L[0][0]
l1 = L[0][1]
for i in L:
    if l0 < i[0]:
        l0 = i[0]

    if l1 > i[1]:
        l1 = i[1]

if N < l0:
    print(0)
elif N < l1:
    print(N - l0 + 1)
else:
    print(l1 - l0 + 1)


Failing test case input:
8 3
3 6
7 3
1 11

Expected output:
0


Actual output:
-3


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
L = [list(map(int, input().split())) for i in range(M)]

l0 = L[0][0]
l1 = L[0][1]
for i in L:
    if l0 < i[0]:
        l0 = i[0]

    if l1 > i[1]:
        l1 = i[1]

if l1 < l0:
    print(0)
else:
    print(l1 - l0 + 1)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int,input().split())
L = []
R = []
for _ in range(M):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)


print(min(R)-max(L)+1)

Failing test case input:
10 3
3 4
7 7
8 9

Expected output:
0


Actual output:
-3


Fixed submission (verdict: Accepted):
N, M = map(int,input().split())
L = []
R = []
for _ in range(M):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)


print(max(min(R)-max(L)+1,0))
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
l_lst = list()
for i in range(m):
    l_lst.append(input().split())

for i in range(0, len(l_lst)):
    for j in range(0, len(l_lst[i])):
        l_lst[i][j] = int(l_lst[i][j])

temp_cnt = 0
cnt = 0
for i in range(1, n+1):
    for j in range(0, len(l_lst)):
        if l_lst[j][0] <= i and i <= l_lst[j][1]:
            temp_cnt += 1
        if temp_cnt == len(l_lst):
            cnt += 1
            temp_cnt = 0

print(cnt)

Failing test case input:
15 3
3 2
4 7
3 11

Expected output:
0


Actual output:
4


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
l_lst = list()
for i in range(m):
    l_lst.append(input().split())

for i in range(0, len(l_lst)):
    for j in range(0, len(l_lst[i])):
        l_lst[i][j] = int(l_lst[i][j])

max_lst = list()
min_lst = list()
for i in range(0, len(l_lst)):
    max_lst.append(l_lst[i][0])
    min_lst.append(l_lst[i][1])

max_int = max(max_lst)
min_int = min(min_lst)

cnt = 0
for i in range(1, n+1):
    if max_int <= i and i <= min_int:
        cnt += 1

print(cnt)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
l, r = map(int, input().split())
A = [l, r]
for i in range(1, m):
  l, r = map(int, input().split())
  if A[0] < l:
    A[0] = l
  if A[1] > r:
    A[1] = r
print(r-l+1)

Failing test case input:
10 3
0 2
4 9
13 14

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
l, r = map(int, input().split())
L = [l]
R = [r]
for i in range(m-1):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)

L.sort()
R.sort()

n =  R[0] -L[m-1] +1
if n > 0:
    print(n)
else:
    print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
l = 0
r = n
for i in range(m):
    lt, rt = map(int, input().split())
    l = max(l, lt)
    r=min(r,rt)
print(r-l+1)


Failing test case input:
10 3
3 2
7 9
6 9

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
l = 0
r = n
for i in range(m):
    lt, rt = map(int, input().split())
    l = max(l, lt)
    r = min(r, rt)
if(l<=r):
    print(r - l + 1)
else:
    print(0)

Problem: p03037
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,M=map(int,input().split())
L_max=0
R_min=10**9
for i in range(M):
  L,R=map(int,input().split())
  L_max=max(L_max,L)
  R_min=min(R_min,R)
print(R_min-L_max+1)


Failing test case input:
8 3
1 7
14 7
2 11

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
L_max=0
R_min=10**9
for i in range(M):
  L,R=map(int,input().split())
  L_max=max(L_max,L)
  R_min=min(R_min,R)
print(R_min-L_max+1 if R_min>=L_max else 0)
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = [int(s) for s in input().split()]
l=1
r=N
for i in range(M):
  x,y = [int(s) for s in input().split()]
  l=max([x,l])
  r=min([y,r])
print(r-l+1)

Failing test case input:
4 2
1 3
2 0

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
N,M = [int(s) for s in input().split()]
l=1
r=N
for i in range(M):
  x,y = [int(s) for s in input().split()]
  l=max([x,l])
  r=min([y,r])
print(max([r-l+1,0]))

Problem: p03037
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m=list(map(int, input().split()))
l = 0
r = float("inf")
for _ in range(m):
    a,b = list(map(int, input().split()))
    l = max(l,a)
    r = min(r,b)

print(r-l+1)

Failing test case input:
14 3
3 2
4 7
8 14

Expected output:
0


Actual output:
-5


Fixed submission (verdict: Accepted):
n,m=list(map(int, input().split()))
l = 0
r = float("inf")
for _ in range(m):
    a,b = list(map(int, input().split()))
    l = max(l,a)
    r = min(r,b)

ans = r-l+1
if r < l:
    print(0)
elif ans <= n:
    print(ans)
else:
    print(n)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m  = map(int, input().split())

a_max = -1
b_min = 999999999999999

for i in range(m):
    a, b = map(int, input().split())
    
    a_max = max(a_max, a)
    b_min = min(b_min, b)
    
print(b_min - a_max + 1)

Failing test case input:
10 3
3 2
7 7
6 11

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
n, m  = map(int, input().split())

a_max = -1
b_min = 999999999999999

for i in range(m):
    a, b = map(int, input().split())
    
    a_max = max(a_max, a)
    b_min = min(b_min, b)

ans = max(b_min - a_max + 1, 0)
print(ans)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
card =[list(map(int,input().split())) for i in range(m)]
r = card[0][0]
R = card[0][1]
for i in range(m):
    if  r < card[i][0]:
        r = card[i][0]
for i in range(m):
    if card[i][1] < R:
        R = card[i][1]

print(R - r + 1)


Failing test case input:
8 3
0 1
7 7
1 11

Expected output:
0


Actual output:
-5


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
card =[list(map(int,input().split())) for i in range(m)]
r = card[0][0]
R = card[0][1]
for i in range(m):
    if  r < card[i][0]:
        r = card[i][0]
for i in range(m):
    if card[i][1] < R:
        R = card[i][1]
ans = max(0,R - r + 1)
print(ans)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())
l = 0
r = n
for i in range(m):
  ll,rr = map(int,input().split())
  l = max(l,ll)
  r = min(r,rr)
print(r-l+1)

Failing test case input:
10 3
3 2
4 7
9 14

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
l = 0
r = n
for i in range(m):
  ll,rr = map(int,input().split())
  l = max(l,ll)
  r = min(r,rr)
if r-l+1 >= 0:
  print(r-l+1)
else:
  print(0)
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



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


max_left = 0
min_right = N


for i in range(M):
    L, R = map(int, input().split())
    max_left = max(max_left, L)
    min_right = min(min_right, R)


ans = min_right - max_left + 1
print(ans)


Failing test case input:
20 3
0 2
4 7
9 14

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):



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


max_left = 0
min_right = N


for i in range(M):
    L, R = map(int, input().split())
    max_left = max(max_left, L)
    min_right = min(min_right, R)


if max_left>min_right:
    print(0)
else:
    ans = min_right - max_left + 1
    print(ans)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())

s=[]
l= 0
r = n
for i in range(m):
    ln,rn=map(int,input().split())
    if ln>l:
        l=ln
    if rn<r:
        r=rn
print(r-l+1)


Failing test case input:
10 3
3 2
10 7
6 5

Expected output:
0


Actual output:
-7


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())

s=[]
l= 0
r = n
for i in range(m):
    ln,rn=map(int,input().split())
    if ln>l:
        l=ln
    if rn<r:
        r=rn
if r-l+1>0:
    print(r-l+1)
else:
    print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int, input().split())
minn, maxn = 1, n
for i in range(m):
	l, r = map(int,input().split())
	minn, maxn = max(minn, l), min(maxn, r)
print(maxn-minn+1)

Failing test case input:
10 3
3 2
7 15
6 9

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
n,m = map(int, input().split())
minn, maxn = 1, n
for i in range(m):
	l, r = map(int,input().split())
	minn, maxn = max(minn, l), min(maxn, r)
print(max(maxn-minn+1, 0))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


NM = [int(i) for i in input().split()]
LR = []
for i in range(NM[1]):
    LR.append([int(i) for i in input().split()])

mi = LR[0][0]
ma = LR[0][1]
for i in range(NM[1]):
    if LR[i][0] > mi:
        mi = LR[i][0]
    if LR[i][1] < ma:
        ma = LR[i][1]


if NM[0] >= ma:
    print(ma-mi+1)
elif NM[0] < ma and NM[0] > mi:
    print(NM[0]-mi+1)
elif NM[0] <= mi:
    print(0)

Failing test case input:
8 3
6 6
7 3
1 11

Expected output:
0


Actual output:
-3


Fixed submission (verdict: Accepted):


NM = [int(i) for i in input().split()]
LR = []
for i in range(NM[1]):
    LR.append([int(i) for i in input().split()])

mi = LR[0][0]
ma = LR[0][1]
for i in range(NM[1]):
    if LR[i][0] > mi:
        mi = LR[i][0]
    if LR[i][1] < ma:
        ma = LR[i][1]


if ma < mi:
    print(0)
elif NM[0] >= ma:
    print(ma-mi+1)
elif NM[0] < ma and NM[0] > mi:
    print(NM[0]-mi+1)
elif NM[0] <= mi:
    print(0)
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


N, M = map(int, input().split())
for i in range(M):
    l, r = map(int, input().split())
    if i == 0:
        R = r
else:
    L = l

if L <= R:
    print(R-L+1)
else:
    print(0)


Failing test case input:
8 3
-1 1
7 7
1 11

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


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

left = max(L)
right = min(R)

if left <= right:
    print(right-left+1)
else:
    print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = list(map(int,input().split()))
L = 0
R = N

for i in range(M):
    tL,tR = list(map(int,input().split()))
    if tL > L:
        L = tL
    if tR < R:
        R = tR
    print(L,R)
print(R-L+1)

Failing test case input:
4 2
1 3
2 0

Expected output:
0


Actual output:
1 3
2 0
-1


Fixed submission (verdict: Accepted):
N,M = list(map(int,input().split()))
L = 1
R = N+1
ans = N*2

for i in range(M):
    tL,tR = list(map(int,input().split()))
    if tR < L or R < tL:
        ans = 0
        break
    if tL > L:
        L = tL
    if tR < R:
        R = tR

print(min(ans,R-L+1))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i]=map(int,input().split())
a=L[0]
for i in range(M):
  if a<L[i]:
    a=L[i]
b=R[0]
for i in range(M):
  if b>R[i]:
    b=R[i]
if b-a+1>1: 
  print(b-a+1)
else:
  print("0")

Failing test case input:
8 1
6 6
7 3
1 11

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i]=map(int,input().split())
a=L[0]
for i in range(M):
  if L[i]>a:
    a=L[i]
  else:
    a=a
b=R[0]
for i in range(M):
  if R[i]<b:
    b=R[i]
  else:
    b=b
if b-a<0:
  print("0")
else:
  print(b-a+1)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

input = sys.stdin.readline

n, m = map(int, input().split())

l_list = []
r_list = []

for _ in range(m):
    l, r = map(int, input().split())
    l_list.append(l)
    r_list.append(r)

print(min(r_list) - max(l_list) + 1)


Failing test case input:
8 3
1 8
14 7
2 10

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
import sys

input = sys.stdin.readline

n, m = map(int, input().split())

l_list = []
r_list = []

for _ in range(m):
    l, r = map(int, input().split())
    l_list.append(l)
    r_list.append(r)

l_maybe_answer = max(l_list)
r_maybe_answer = min(r_list)

if l_maybe_answer <= r_maybe_answer:
    print(min(r_list) - max(l_list) + 1)
else:
    print(0)
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())

s = 0
e = n-1

for _ in range(m):
  l,r = map(int,input().split())
  
  s = max(s,l)
  e = min(e,r)
  
print(max(e-s+1,0))

Failing test case input:
4 2
1 4
2 4

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())

s = 1
e = n

for _ in range(m):
  l,r = map(int,input().split())
  
  s = max(s,l)
  e = min(e,r)
  
print(max(e-s+1,0))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())

max_l=0
min_r=float('inf')

for i in range(m):
    l,r=map(int,input().split())
    max_l=max(max_l,l)
    min_r=min(min_r,r)
    
print(min_r-max_l+1)
    

Failing test case input:
17 3
3 2
3 7
6 9

Expected output:
0


Actual output:
-3


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())

L=[0]*m
R=[0]*m

for i in range(m):
    l,r=map(int,input().split())
    L[i]=l
    R[i]=r
ans=min(R)-max(L)+1
print(ans if ans>0 else 0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
k = []
l = []
r = []

for i in range(m):
  k = list(map(int, input().split()))
  l.append(k[0])
  r.append(k[1])

ans = min(r) - max(l) + 1
print(ans)

Failing test case input:
15 3
3 2
4 7
3 11

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
k = []
l = []
r = []

for i in range(m):
  k = list(map(int, input().split()))
  l.append(k[0])
  r.append(k[1])

if max(l) <= min(r):
  ans = min(r) - max(l) + 1
else:
  ans = 0
print(ans)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
L = 1
R = N

for i in LR:
    if i[0] > L:
        L = i[0]
    
    if i[1] < R:
        R = i[1]

print(R-L+1)

Failing test case input:
10 3
3 6
11 7
1 9

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
L = 1
R = N

for i in LR:
    if i[0] > L:
        L = i[0]
    
    if i[1] < R:
        R = i[1]

print(max(0, R-L+1))
Problem: p03037
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys

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

tmp1 = 0
tmp2 = float('inf')
val = [[] for i in range(M)]
ans = 0
for i in range(M):
    L,R = map(int, input().split())
    val[i].append(L)
    val[i].append(R)
    if R < tmp1:
        print(ans)
        sys.exit()
    if L > tmp1:
        tmp1 = L
    if R < tmp2:
        tmp2 = R
print(tmp2-tmp1+1)

Failing test case input:
14 3
3 2
4 7
9 14

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
import sys

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

tmp1 = 0
tmp2 = float('inf')
val = [[] for i in range(M)]
ans = 0
for i in range(M):
    L,R = map(int, input().split())
    val[i].append(L)
    val[i].append(R)
    if R < tmp1:
        print(ans)
        sys.exit()
    if L > tmp1:
        tmp1 = L
    if R < tmp2:
        tmp2 = R
if tmp2-tmp1+1 < 0:
    print(0)
else:
    print(tmp2-tmp1+1)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())
l,r = 1,n
for i in range(m):
  L,R = map(int,input().split())
  L = max(l,L)
  R = min(r,R)
print(max(0,L-R+1))

Failing test case input:
10 2
3 6
11 0
0 9

Expected output:
0


Actual output:
12


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
l,r = 1,n
for i in range(m):
  L,R = map(int,input().split())
  l = max(l,L)
  r = min(r,R)
print(max(0,r-l+1))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
gate=[input() for __ in range(M)]
s,e=map(int,gate[0].split())
for n in gate:
    pre_s,pre_e=map(int,n.split())
    s=(s if s>pre_s else pre_s)
    e=(e if e<pre_e else pre_e)

print(e+1-s)


Failing test case input:
10 3
3 2
4 7
6 11

Expected output:
0


Actual output:
-3


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
gate=[input() for __ in range(M)]
s,e=map(int,gate[0].split())
for n in gate:
    pre_s,pre_e=map(int,n.split())
    s=(s if s>pre_s else pre_s)
    e=(e if e<pre_e else pre_e)

print(e+1-s if e>=s else 0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
idCards, gates = input().split(" ")
idCards = int(idCards)
gates = int(gates)
minNum = []
maxNum = []

for count in range(0, gates, 1):
    num1, num2 = input().split(" ")
    minNum.append(int(num1))
    maxNum.append(int(num2))

minId = max(minNum)
maxId = min(maxNum)

print(maxId - minId + 1)


Failing test case input:
10 3
3 2
7 7
6 5

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
import sys
idCards, gates = input().split(" ")
idCards = int(idCards)
gates = int(gates)
minNum = []
maxNum = []

if idCards > 1000000 or gates > 1000000:
    sys.exit()

for count in range(0, gates, 1):
    num1, num2 = input().split(" ")
    minNum.append(int(num1))
    maxNum.append(int(num2))

minId = max(minNum)
maxId = min(maxNum)
if minId > maxId:
    print("0")
else:
    print((maxId - minId) + 1)
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
l=1
r=100000
for i in range(M):
  L,R=map(int,input().split())
  if L>l:
    l=L
  if R<r:
    r=R
    
print(r-l+1)
  

Failing test case input:
10 3
3 2
7 15
6 9

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
l=1
r=N
for i in range(M):
  L,R=map(int,input().split())
  if L>l:
    l=L
  if R<r:
    r=R
    
if l<=r:
  print(r-l+1)
  
else:
  print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(m)]
print(sorted(lr,key=lambda x:x[1])[0][1]-sorted(lr,key=lambda x:x[0])[-1][0]+1)

Failing test case input:
8 3
3 0
7 7
1 1

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(m)]
a=sorted(lr,key=lambda x:x[1])[0][1]-sorted(lr,key=lambda x:x[0])[-1][0]+1
print(max(a,0))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
l = 1
r = N
for i in range(M):
  L, R = map(int, input().split())
  if l < L:
    l = L
  if r < R:
    r = R
if l > r:
  print(0)
else:
  print(r-l+1)

Failing test case input:
101100 1
1 100110

Expected output:
100110


Actual output:
101100


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
l = 1
r = N
for i in range(M):
  L, R = map(int, input().split())
  if L > l:
    l = L
  if r > R:
    r = R
if l > r:
  print(0)
else:
  print(r-l+1)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def solve(l1, r1, l2, r2):
    if r1 < l2 or r2 < l1:
        return None
    elif l1 < l2 and r1 < r2:
        return [l2, r1]
    elif l1 >= l2 and r1 <= r2:
        return [l1, r1]
    else:
        return [l1, r2]


def main():
    n, m = map(int, input().split())
    ans = [1, n]
    for _ in range(m):
        l, r = map(int, input().split())
        ans = solve(ans[0], ans[1], l, r)
        if ans is None:
            print(0)
            exit(0)
    print(ans[1] - ans[0] + 1)

if __name__ == '__main__':
    main()


Failing test case input:
111100 1
5 100111

Expected output:
100107


Actual output:
100111


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def solve(l1, r1, l2, r2):
    if r1 < l2 or r2 < l1:
        return None
    elif l1 < l2 and r1 < r2:
        return [l2, r1]
    elif l1 >= l2 and r1 <= r2:
        return [l1, r1]
    elif l1 <= l2 and r2 <= r1:
        return [l2, r2]
    else:
        return [l1, r2]


def main():
    n, m = map(int, input().split())
    ans = [1, n]
    for _ in range(m):
        l, r = map(int, input().split())
        
        ans = solve(ans[0], ans[1], l, r)
        
        if ans is None:
            print(0)
            exit(0)
    print(ans[1] - ans[0] + 1)

if __name__ == '__main__':
    main()
Problem: p03037
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from itertools import accumulate
N, M = map(int, input().split())

left = 1
right = M

for i in range(M):
    a,b = map(int, input().split())
    left = max(left,a)
    right = min(right, b)

print(max(0,right-left+1))

















Failing test case input:
101000 1
1 100010

Expected output:
100010


Actual output:
1


Fixed submission (verdict: Accepted):
from itertools import accumulate
N, M = map(int, input().split())

left = 1
right = N

for i in range(M):
    a,b = map(int, input().split())
    left = max(left,a)
    right = min(right, b)

print(max(0,right-left+1))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for m in range(m)]






maxtable1 = sorted(table, key = lambda x: x[0])
maxtable2 = sorted(table, key = lambda x: x[1])

print(maxtable2[0][1] - maxtable1[m-1][0] + 1)

Failing test case input:
10 3
3 2
7 9
6 9

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
n, m = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for m in range(m)]

maxtable1 = sorted(table, key = lambda x: x[0])
maxtable2 = sorted(table, key = lambda x: x[1])

print(max(0, maxtable2[0][1] - maxtable1[m-1][0] + 1))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
a=0
b=n*10**9
for i in range(m):
  x,y=map(int,input().split())
  a=max(a,x)
  b=min(b,y)
ans=b-a+1
print(ans)

Failing test case input:
10 3
3 2
7 7
6 9

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
a=0
b=n*10**9
for i in range(m):
  x,y=map(int,input().split())  
  a=max(a,x)
  b=min(b,y)
if b>=a:
  ans=b-a+1
  print(ans)
else:
  print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(m)]
a = ls[0][0]
b = ls[0][1]
for j in range(1,m):
    a = max(a,ls[j][0])
    b = min(b,ls[j][1])
    print(a)
    print(b)
    if b-a<0:
        print(0)
        sys.exit()
print(b-a+1)

Failing test case input:
10 3
3 2
7 7
6 11

Expected output:
0


Actual output:
7
2
0


Fixed submission (verdict: Accepted):
import sys
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(m)]
a = ls[0][0]
b = ls[0][1]
for j in range(1,m):
    a = max(a,ls[j][0])
    b = min(b,ls[j][1])
    if b-a<0:
        print(0)
        sys.exit()
print(b-a+1)
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(M)]
maxL, minR=-1, N
for L, R in lst:
  L, R=L-1, R-1
  maxL=max(maxL, L)
  minR=min(minR, R)
if minR>maxL:
  print(minR-maxL+1)
else:
  print(0)

Failing test case input:
10 1
6 6
5 7
10 8

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N, M=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(M)]
maxL, minR=-1, N
for L, R in lst:
  L, R=L-1, R-1
  maxL=max(maxL, L)
  minR=min(minR, R)
if minR>=maxL:
  print(minR-maxL+1)
else:
  print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
p=1
q=n
for i in range(m):
  l,r=map(int,input().split())
  if p<l:
    p=l
  if r<q:
    q=r
  if p>q:
    print(0)
    break
print(q-p+1)

Failing test case input:
8 3
1 7
14 7
2 11

Expected output:
0


Actual output:
0
-6


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
p=1
q=n
for i in range(m):
  l,r=map(int,input().split())
  if p<l:
    p=l
  if r<q:
    q=r
  if p>q:
    print(0)
    exit()
print(q-p+1)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int,input().split())
lr = [tuple(map(int,input().split())) for _ in range(M)]
ls = []
rs = []
for i in range(M):
  ls.append(lr[i][0])
  rs.append(lr[i][1])

print(min(rs) - max(ls) + 1)

Failing test case input:
8 3
3 0
7 7
1 9

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
N, M = map(int,input().split())
lr = [tuple(map(int,input().split())) for _ in range(M)]
ls = []
rs = []
for i in range(M):
  ls.append(lr[i][0])
  rs.append(lr[i][1])

print(max(0,min(rs) - max(ls) + 1))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = input().split()
N = int(n)
M = int(m)

listL = []
listR = []
card = N
for i in range(M):
    l, r = input().split()
    L = int(l)
    R = int(r)

    listL.append(L)
    listR.append(R)

maxL = max(listL)
minR = min(listR)

result = minR - maxL + 1
print(result)


Failing test case input:
10 3
3 6
5 7
10 8

Expected output:
0


Actual output:
-3


Fixed submission (verdict: Accepted):
n, m = input().split()
N = int(n)
M = int(m)

listL = []
listR = []
card = N
for i in range(M):
    l, r = input().split()
    L = int(l)
    R = int(r)

    listL.append(L)
    listR.append(R)

maxL = max(listL)
minR = min(listR)

if minR < maxL:
    result = 0
else:
    result = minR - maxL + 1
print(result)
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
data = stdin.readline().split()
N, M = int(data[0]), int(data[1])
left = [None] * M
right = [None] * M
for itr in range(M):
    gate = stdin.readline().split()
    left[itr] = int(gate[0])
    right[itr] = int(gate[1])
print(min(right)-max(left) + 1)

Failing test case input:
6 3
3 0
5 7
1 1

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
from sys import stdin
data = stdin.readline().split()
N, M = int(data[0]), int(data[1])
left = [None] * M
right = [None] * M
for itr in range(M):
    gate = stdin.readline().split()
    left[itr] = int(gate[0])
    right[itr] = int(gate[1])
if (min(right)-max(left) + 1) < 0:
    print(0)
else:
    print(min(right)-max(left) + 1)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())

l = []
r = []
for i in range(m):
    tmp_l,tmp_r = map(int,input().split())
    l.append(tmp_l)
    r.append(tmp_r)

ll = l[0]
rr = r[0]

for i in range(1,m):
    if ll < l[i]:
        ll = l[i]
    if rr > r[i]:
        rr = r[i]

cnt = rr-ll+1
if cnt >= 0:
    print(cnt)


Failing test case input:
10 3
1 2
4 9
13 14

Expected output:
0


Actual output:

Fixed submission (verdict: Accepted):
n,m = map(int,input().split())

l = []
r = []
for i in range(m):
    tmp_l,tmp_r = map(int,input().split())
    l.append(tmp_l)
    r.append(tmp_r)

ll = l[0]
rr = r[0]

for i in range(1,m):
    if ll < l[i]:
        ll = l[i]
    if rr > r[i]:
        rr = r[i]

cnt = rr-ll+1
if cnt >= 1:
    print(cnt)
else:
    print(0)

Problem: p03037
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
    n, m = map(int, input().split())

    card_list = [0] * n

    l_list = []
    r_list = []

    for _ in range(m):
        l, r = map(int, input().split())
        l_list.append(l)
        r_list.append(r)

    max_l = max(l_list)
    min_r = min(r_list)

    print(min_r-max_l+1)

if __name__ == '__main__':
    main()

Failing test case input:
8 3
6 6
7 3
1 11

Expected output:
0


Actual output:
-3


Fixed submission (verdict: Accepted):
def main():
    n, m = map(int, input().split())

    card_list = [0] * n

    l_list = []
    r_list = []

    for _ in range(m):
        l, r = map(int, input().split())
        l_list.append(l)
        r_list.append(r)

    max_l = max(l_list)
    min_r = min(r_list)

    print(min_r-max_l+1 if min_r >= max_l else 0)

if __name__ == '__main__':
    main()

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, (input().split()))

L, R = 1, n
for i in range(m):
    l, r = map(int, input().split())
    L, R = max(L, l), min(R, r)

print(R - L + 1)


Failing test case input:
20 3
0 3
4 7
9 14

Expected output:
0


Actual output:
-5


Fixed submission (verdict: Accepted):
n, m = map(int, (input().split()))

L, R = 1, n
for i in range(m):
    l, r = map(int, input().split())
    L, R = max(L, l), min(R, r)

print(max(R - L + 1, 0))
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N, M = map(int, input().split(" "))
    left = 0
    right = 10**5
    for i in range(M):
        a, b = map(int, input().split(" "))
        left = max(left, a)
        right = min(right, b)
    if not left == 1:
        print(right - left + 1)
    else:
        print(right)


if __name__ == '__main__':
    main()

Failing test case input:
14 3
3 2
4 7
8 14

Expected output:
0


Actual output:
-5


Fixed submission (verdict: Accepted):
def main():
    N, M = map(int, input().split(" "))
    left = 0
    right = N
    for _ in range(M):
        l, r = map(int, input().split(" "))
        left = max(left, l)
        right = min(right, r)
    if right - left < 0:
        print(0)
    else:
        print(right - left + 1)


if __name__ == '__main__':
    main()

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
G=[[] for _ in range(M)]
for i in range (M):
  L,R=map(int,input().split())
  G[i].append([L,R])
small=[]
for i in range(M):
  small.append(G[i][0][0])
s=max(small)
large=[]
for i in range(M):
  large.append(G[i][0][1])
l=min(large)
ans=l-s+1
print(ans)

Failing test case input:
8 3
3 6
7 3
1 11

Expected output:
0


Actual output:
-3


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
G=[[] for _ in range(M)]
for i in range (M):
  L,R=map(int,input().split())
  G[i].append([L,R])
small=[]
for i in range(M):
  small.append(G[i][0][0])
s=max(small)
large=[]
for i in range(M):
  large.append(G[i][0][1])
l=min(large)
if s<=l:
  ans=l-s+1
else:
    ans=0
print(ans)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())
left,right = 1,n
for i in range(m):
    l,r = map(int,input().split())
    left = max(left,1)
    right = min(right,r)
print(max(0,right-left+1))


Failing test case input:
3 2
1 1
2 4

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n,m = map(int ,input().split())
left,right = 1,n
for i in range(m):
    l,r = map(int,input().split())
    left = max(left,l)
    right = min(right,r)
print(max(0,right - left + 1))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int, input().split())
lmax=0
rmin=n

for i in range(m):
  L,R=map(int, input().split())
  lmax=max(L,lmax)
  rmin=min(R,rmin)
print(rmin-lmax+1)

Failing test case input:
10 2
3 6
11 0
0 9

Expected output:
0


Actual output:
-10


Fixed submission (verdict: Accepted):
n,m=map(int, input().split())
lmax=0
rmin=1000000

for i in range(m):
  L,R=map(int, input().split())
  lmax=max(L,lmax)
  rmin=min(R,rmin)
ans=max(rmin-lmax+1,0)
print(ans)
Problem: p03037
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):






n,m = map(int,input().split())
max_l = 0
min_r = n
for i in range(m):
  l,r = map(int,input().split())
  if max_l <  l:
    max_l = l
  if min_r > r:
    min_r = r
print(min_r - max_l +1)
  


Failing test case input:
10 3
3 2
4 7
9 14

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):






n,m = map(int,input().split())
max_l = 0
min_r = n
for i in range(m):
  l,r = map(int,input().split())
  if max_l <  l:
    max_l = l
  if min_r > r:
    min_r = r
ans = 0
if min_r - max_l +1 > 0:
  ans = min_r - max_l +1
print(ans)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i]=map(int,input().split())
a=L[0]
for i in range(M):
  if a<L[i]:
    a=L[i]
b=R[0]
for i in range(M):
  if b>R[i]:
    b=R[i]
print(b-a+1)

Failing test case input:
4 2
1 0
2 6

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i]=map(int,input().split())
a=L[0]
for i in range(M):
  if L[i]>a:
    a=L[i]
  else:
    a=a
b=R[0]
for i in range(M):
  if R[i]<b:
    b=R[i]
  else:
    b=b
if b-a<0:
  print("0")
else:
  print(b-a+1)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
L, R = map(int, input().split())
if M == 1:
    print(R - L + 1)
for _ in range(M-1):
    l, r = map(int, input().split())
    if l <= R and L <= r:
        L = max(L, l)
        R = min(R, r)
    else:
        print(0)
        exit()
print(R - L + 1)


Failing test case input:
101100 1
1 100100

Expected output:
100100


Actual output:
100100
100100


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
L, R = map(int, input().split())
if M == 1:
    print(R - L + 1)
    exit()
for _ in range(M-1):
    l, r = map(int, input().split())
    if l <= R and L <= r:
        L = max(L, l)
        R = min(R, r)
    else:
        print(0)
        exit()
print(R - L + 1)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n,m = map(int,input().split())
lr = [list(map(int,input().split())) for ii in range(m)]
L = [lr[jj][0] for jj in range(m) ]
R = [lr[jj][1] for jj in range(m) ]

print(min(R)-max(L)+1)


Failing test case input:
8 3
1 7
14 7
2 10

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):

n,m = map(int,input().split())
lr = [list(map(int,input().split())) for ii in range(m)]
L = [lr[jj][0] for jj in range(m) ]
R = [lr[jj][1] for jj in range(m) ]

if min(R)-max(L) < 0:
    print(0)
else:
    print(min(R)-max(L)+1)
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for _ in range(M)]
lmax = 1
rmin = N
for l, r in LR:
    lmax = max(lmax, l)
    rmin = min(rmin, r)
print(rmin - lmax + 1)


Failing test case input:
10 3
1 2
4 9
13 14

Expected output:
0


Actual output:
-10


Fixed submission (verdict: Accepted):
N, M = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for _ in range(M)]
lmax = 1
rmin = N
for l, r in LR:
    lmax = max(lmax, l)
    rmin = min(rmin, r)
print(max([0, rmin - lmax + 1]))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n ,m = map(int, input().split())
L = []
R = []
for i in range(m):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

print(min(R) - max(L) + 1)

Failing test case input:
9 3
3 2
7 15
6 9

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
n ,m = map(int, input().split())
L = []
R = []
for i in range(m):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
if max(L) <= min(R):
    print(min(R) - max(L) + 1)
else:
    print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = list(map(int, sys.stdin.buffer.readline().split()))
    LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
    mi = 0
    mx = 10 ** 5 + 1

    for lr in LR:
        l = lr[0]
        r = lr[1]
        mi = max(mi, l)
        mx = min(mx, r)
        print(mi, mx)

    print(mx - mi + 1)


if __name__ == '__main__':
    main()


Failing test case input:
10 3
3 2
10 7
6 5

Expected output:
0


Actual output:
3 2
10 2
10 2
-7


Fixed submission (verdict: Accepted):
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = list(map(int, sys.stdin.buffer.readline().split()))
    mi = 1
    mx = N

    for m in range(M):
        L, R = map(int, sys.stdin.buffer.readline().split())
        mi = max(mi, L)
        mx = min(mx, R)

    print(max(0, mx - mi + 1))


if __name__ == '__main__':
    main()

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
info=[]
for i in range(m):
    info.append(list(map(int,input().split())))
start,goal=info[0][0],info[0][1]
c=0

for i in range(1,m):
    start=max(start,info[i][0])
    goal=min(goal,info[i][1])
    if start>=goal:
        c=1
        break
    
if c==0:
    print(goal-start+1)
else:
    print(0)

Failing test case input:
8 3
1 7
7 7
1 11

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
info=[]
for i in range(m):
    info.append(list(map(int,input().split())))
start,goal=info[0][0],info[0][1]
c=0

for i in range(1,m):
    start=max(start,info[i][0])
    goal=min(goal,info[i][1])
    if start>goal:
        c=1
        break
    
if c==0:
    print(goal-start+1)
else:
    print(0)
Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
l = 0
r = n
for i in range(m):
    lt, rt = map(int, input().split())
    if (lt > l):
        l = lt
    if (rt < r):
        r = rt
if (r <l):
    print(l,r)
    print(0)
else:
    print(r-l+1)


Failing test case input:
8 3
1 7
14 7
2 10

Expected output:
0


Actual output:
14 7
0


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
l = 0
r = n
for i in range(m):
    lt, rt = map(int, input().split())
    l = max(l, lt)
    r = min(r, rt)
if(l<=r):
    print(r - l + 1)
else:
    print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
c,g=map(int,input().split())

st=[]
en=[]

for i in range(g):
	s,e=map(int,input().split())
	st.append(s) 
	en.append(e)

res=min(en)-max(st)+1
print(res)

Failing test case input:
8 3
-1 1
7 7
1 11

Expected output:
0


Actual output:
-5


Fixed submission (verdict: Accepted):
c,g=map(int,input().split())

st=[]
en=[]

for i in range(g):
	s,e=map(int,input().split())
	st.append(s) 
	en.append(e)

res=min(en)-max(st)+1
print(max(res,0))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
num = [list(map(int, input().split())) for _ in range(m)]
num1 = 1
num2 = n

for j in range(m):
  num1 = max(num[j][0], num1)
  num2 = min(num[j][1], num2)

print(num2 - num1 + 1)

Failing test case input:
8 3
1 7
14 7
2 10

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
num = [list(map(int, input().split())) for _ in range(m)]
num1 = 1
num2 = n

for j in range(m):
  num1 = max(num[j][0], num1)
  num2 = min(num[j][1], num2)

ans = num2 - num1 + 1

if ans > 0:
  print(ans)
else:
  print(0)

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
llist = []
rlist = []
for i in range(m):
    l, r = map(int, input().split())
    llist.append(l)
    rlist.append(r)
print(min(rlist)-max(llist)+1)


Failing test case input:
10 3
3 2
4 7
3 11

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
llist = []
rlist = []
for i in range(m):
    l, r = map(int, input().split())
    llist.append(l)
    rlist.append(r)
print(max((min(rlist)-max(llist)+1), 0))

Problem: p03037
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
left=0
right=n
for i in range(m):
    l,r=map(int,input().split())
    left=max(l,left)
    right=min(r,right)
print(right-left+1)

Failing test case input:
8 3
3 6
7 3
1 11

Expected output:
0


Actual output:
-3


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
left=0
right=n
for i in range(m):
    l,r=map(int,input().split())
    left=max(l,left)
    right=min(r,right)
print(max(0,right-left+1))