Problem:


Score : 300 points

Problem Statement

We have N ID cards, and there are M gates.

We can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards.

How many of the ID cards allow us to pass all the gates alone?

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq L_i \leq R_i \leq N

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M

Output

Print the number of ID cards that allow us to pass all the gates alone.

Sample Input 1

4 2
1 3
2 4

Sample Output 1

2

Two ID cards allow us to pass all the gates alone, as follows:

The first ID card does not allow us to pass the second gate.

The second ID card allows us to pass all the gates.

The third ID card allows us to pass all the gates.

The fourth ID card does not allow us to pass the first gate.

Sample Input 2

10 3
3 6
5 7
6 9

Sample Output 2

1

Sample Input 3

100000 1
1 100000

Sample Output 3

100000



Sample input:
4 2
1 3
2 4


Sample output:
2

Submission status: Wrong Answer

Solution code:
N, M = [int(x) for x in input().split()]
L = []
R = []
for _ in range(M):
  l, r = [int(x) for x in input().split()]
  L.append(l)
  R.append(r)

under = max(L)
up = min(R)
print(up - under + 1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
k_1 = []
k_2 = []
for i in range(M):
  l,r = map(int,input().split())
  k_1.append(l)
  k_2.append(r)
if min(k_2)>N:
  S = N
else:
  S = min(k_2)
print(S-max(k_1)+1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
k_1 = []
k_2 = []
for i in range(M):
  l,r = map(int,input().split())
  k_1.append(l)
  k_2.append(r)
print(min(k_2)-max(k_1)+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())

lm = 0
rm = 10**5+1
for _ in range(M):
    l, r = map(int, input().split())
    lm = max(lm, l)
    rm = min(rm, r)

print(rm-lm+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L = []
R = []
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)

under = max(L)
up = min(R)
print(up - under + 1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L = []
R = []
ans = 0
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
ans = max(0,min(R) - min(L) + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(M)]
count = 0
for i in range(N):
  for j,k in LR:
    if i >= j and i <= k:
      count += 1
print(count)

Submission status: Wrong Answer

Solution code:
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 ans <= n:
    print(ans)
else:
    print(n)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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(min(n, r-l+1))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def main():
    N,M = map(int,input().split())
    L = []
    R = []
    for _ in range(M):
        l,r = map(int,input().split())
        L.append(l)
        R.append(r)
    L.sort(reverse=True)
    R.sort()
    lmax = L[0]
    rmin = R[0]
    print(max(0,rmin-lmax)+1)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def main():
    N,M = map(int,input().split())
    LR = [list(map(int,input().split())) for i in range(M)]
    LR.sort(key=lambda x: x[0],reverse=True)
    lmax = LR[0][0]
    LR.sort(key=lambda x: x[1])
    rmin = LR[0][1]
    print(rmin-min(rmin,lmax)+1)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def main():
    N,M = map(int,input().split())
    LR = [list(map(int,input().split())) for i in range(M)]
    LR.sort(key=lambda x: x[0],reverse=True)
    lmax = LR[0][0]
    LR.sort(key=lambda x: x[1])
    rmin = LR[0][1]
    print(rmin-lmax+1)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
li = []
ri = []

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

ans = min(ri)-max(li)+1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
L=0
R=N
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)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = []
flag = True
for i in range(m):
    l, r = map(int, input().split())
    if i == 0: 
        l1 = l
        r1 = r
    else:
        if l1 < l:
            l1 = l
        elif r1 > r:
            r1 = r
if flag: print(r1-l1+1)
else: print(0)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = []
flag = True
for i in range(m):
    l, r = map(int, input().split())
    if i == 0: 
        l1 = l
        r1 = r
    else:
        if r < l1 or r1 < l:
            flag = False
            exit()
        elif l1 < l:
            l1 = l
        elif r1 > r:
            r1 = r
if flag: print(r1-l1+1)
else: print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
LR=[list(map(int,input().split())) for i in range(M)]
l=LR[0][0]
r=LR[0][1]
for lr in LR:
    if l<lr[0]:
        l=lr[0]
    if lr[1]<r:
        r=lr[1]
print(r-l+1)

Submission status: Wrong Answer

Solution code:
def main():
  IN=open(0).read().split()[2:];L,R=map(int,[sorted(IN[::2])[-1],sorted(IN[1::2])[0]]);print(R-L+1 if R>=L else 0)
if __name__=="__main__":
  main()

Submission status: Wrong Answer

Solution code:
def main():
  IN= open(0).read().split()[2:];L,R=map(int,[max(IN[::2]),min(IN[1::2])]);print(R-L+1 if R-L>0 else 0)
if __name__=="__main__":
  main()

Submission status: Wrong Answer

Solution code:


def main():
    n,m = map(int,input().split())
    
    lm = 1
    rm = n
    for i in range(m):
        l,r = map(int,input().split())
        lm = max(lm,l)
        rm = min(rm,r)
    
    print(rm-lm+1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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())

print(min(min(r) - max(l)+1, n))

Submission status: Wrong Answer

Solution code:
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())

print(max(min(r) - max(l)+1, n))

Submission status: Wrong Answer

Solution code:
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())

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

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
ar = [0,N]
for m in range(M):
    l,r = map(int, input().split())
    if l>ar[0]:
        ar[0] = l
    if r<ar[1]:
        ar[1]=r
print(ar[1]-ar[0]+1)

Submission status: Wrong Answer

Solution code:
#前のやつだとTLEする
#こんなことしなくても最小と最大を更新していけばおｋ
n,m=map(int,input().split())
l,r=map(int,input().split())
l_max,r_min=l,r
for i in range(m-1):
    l,r=map(int,input().split())
    if l_max<l: l_max=l
    if r_min>r: r_min=r
print(r_min-l_max+1)

Submission status: Wrong Answer

Solution code:
n,M=list(map(int,input().split()))
x=set(range(10**5))
for m in range(M):
  l,r=list(map(int,input().split()))
  x=set(range(l,r+1))&x
print(len(x))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
min_ID = 0
max_ID = N
for _ in range(M):
    L, R = map(int, input().split())
    if min_ID < L:
        min_ID = L
    if max_ID > R:
        max_ID = R
print(max_ID - min_ID + 1)

Submission status: Wrong Answer

Solution code:
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()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())

l = -float("inf")
r = float("inf")

for i in range(M):
    l_i, r_i = map(int, input().split())
    if l_i > l:
        l = l_i
    if r_i < r:
        r = r_i

if (r - l) > N:
    print(N)
else:
    print(r-l+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())

cards = list(range(1, N+1))
for _ in range(M):
    l, r = map(int, input().split())
    if l > cards[-1] or r < cards[0]:
        continue
    cards = list(set(cards) & set(range(l, r+1)))
print(len(cards))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
lmax = -1
rmin = 10**100
for i in range(m):
    l,r = map(int,input().split())
    lmax = max(l,lmax)
    rmin  = min(r,rmin)
print(rmin - lmax + 1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
mn = 0
mx = 10**5
for i in range(m):
    l,r = map(int,input().split())
    if mn < l:
        mn = l
    if mx > r:
        mx = r
if mn < mx:
    print(mx-mn+1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
mn = 0
mx = 10**5
for i in range(m):
    l,r = map(int,input().split())
    if mn < l:
        mn = l
    if mx > r:
        mx = r
print(mx-mn+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l,r=[],[]

for i in range(m):
  ll,rr=map(int,input().split())
  l.append(ll)
  r.append(rr)
  
print(min(r) - max(l) + 1 if min(r)-max(l) > 0 else 0)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l,r=[],[]

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,m  = map(int, input().split())
L = 0
R = 500000
for i in range(m):
    l,r = map(int, input().split())
    #print(l,r)
    L = max(L, l)
    R = min(R, r)
    l = 0
    r = 0

print(R-L+1)

Submission status: Wrong Answer

Solution code:
n,m  = map(int, input().split())
l = []
c = []
for i in range(m):
    if n != 1:
        a,b = map(int, input().split())
        for j in range(a,b+1):
            l.append(j)
l = sorted(l)
#print(l)
x = 0
y = 0
for k in range(len(l)-1):
    if l[k] ==l[k+1]:
        x+=1
        if x == m-1:
            y += 1
            x = 0
    else:
        x = 0
        continue

if n == 1:
    print(m)
elif y == 0:
    print(n)
else:
    print(y)

Submission status: Wrong Answer

Solution code:
n,m  = map(int, input().split())
l = []
c = []
for i in range(m):
    a,b = map(int, input().split())
    for j in range(a,b+1):
        l.append(j)
    l = sorted(l)
#print(l)
x = 0
y = 0
for k in range(len(l)-1):
    if l[k] ==l[k+1]:
        x+=1
        if x == m-1:
            y += 1
    else:
        x = 0
        continue

if y == 0:
    print(n)
else:
    print(y)

Submission status: Wrong Answer

Solution code:
n,m  = map(int, input().split())
l = []
c = []
for i in range(m):
    a,b = map(int, input().split())
    for j in range(a,b+1):
        l.append(j)
    l = sorted(l)
#print(l)
x = 0
y = 0
for k in range(len(l)-1):
    if l[k] ==l[k+1]:
        x+=1
        if x == m-1:
            y += 1
    else:
        x = 0
        continue

if y == 0:
    print(1)
else:
    print(y)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(M)]

ans_left,ans_right=LR[0][0],LR[0][1]
for lr in LR:
    left,right=lr[0],lr[1]
    if ans_left<left:
        ans_left=left
    if ans_right>right:
        ans_right=right
        
if right<left:
    ans=0
else:
    ans=ans_right-ans_left+1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
cards = []
for i in range(m):
    cards.append(list(map(int,input().split())))

min = cards[0][0]
max = cards[0][1]

for i in range(m):
    if cards[i][0] > min:
        min = cards[i][0]
    if cards[i][1] < max:
        max = cards[i][1]

if max >min:
    print(max - min + 1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
cards = []
for i in range(m):
    cards.append(list(map(int,input().split())))

min = cards[0][0]
max = cards[0][1]

for i in range(m):
    if cards[i][0] > min:
        min = cards[i][0]
    if cards[i][1] < max:
        max = cards[i][1]

print(max - min + 1)

Submission status: Wrong Answer

Solution code:
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(0)
else:
    print(min(R)-min(L)+1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())

left=1
right=pow(10,5)

for i in range(M):
    L,R=map(int,input().split())
    left=max(left, L)
    right=min(right,R)
ans=right-left+1
print(N if ans>N else ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())

left=1
right=pow(10,5)

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

print(right-left+1)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
l = []
for _ in range(m):
    data = list(map(int,input().split()))
    l.append(data)

l_max=0
r_min=10**9
for tmp in l:
    l=tmp[0]
    r=tmp[1]
    if l_max < l:
        l_max=l
    if r_min > r:
        r_min=r
print(r_min-l_max+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = []
r = []
for i in range(m):
  li, ri = map(int, input().split())
  l.append(li)
  r.append(ri)
maxl = -10**5-1
minr = 10**5+1
for i in range(m):
  maxl = max(maxl, l[i])
  minr = min(minr, r[i])
print(minr - maxl + 1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
L = [0] * m
R = [0] * m
for i in range(m):
    L[i], R[i] = list(map(int, input().split()))
print(min(R) - max(L) + 1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
mi = 1
ma = 100000
for i in range(m):
    l,r = map(int,input().split())
    if l > mi:
        mi = l
    if r < ma:
        ma = r
print(ma-mi + 1)

Submission status: Wrong Answer

Solution code:
import sys
N,M=map(int,input().split())
_min,_max=map(int,input().split())
for i in range(M-1):
   L,R=map(int,input().split())
   if R<_min or L>_max:
       print(0)
       sys.exit()
   _min,_max=max(_min,L),min(_max,R)
print(_min+1-_max)

Submission status: Wrong Answer

Solution code:
from functools import reduce
N,M=map(int,input().split())
_max,_min=map(int,input().split())
for i in range(M-1):
   L,R=map(int,input().split())
   _max,_min=max(_max,L),min(_min,R)
print(_min+1-_max)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()
def main():
    N, M = map(int, input().split())
    dict = {}
    for _ in range(M):
        L, R = map(int, input().split())
        for x in range(L, R+1):
            if x in dict:
                dict[x] += 1
            else:
                dict[x] = 1
    return sum([1 for k, v in dict.items() if v == M])
main()

Submission status: Wrong Answer

Solution code:
import sys

n, m, *lr = map(int, sys.stdin.read().split())
lr = zip(*[iter(lr)] * 2)

def main():
    le, ra = 1, n
    for l, r in lr:
        le = max(l, le)
        ra = min(r, ra)
    return ra - le + 1

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
N_ID, M_gate = map(int, input().split())
mini = float('inf')
MAX = 0

for i in range(M_gate):
    L, R = map(int, input().split())
    MAX = max(MAX, L)
    mini = min(mini, R)

answer = mini - MAX + 1
print(answer)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(m)]

l_max, r_min = 1, 10**5
for di in d:
    l_max = max(l_max, di[0])
    r_min = min(r_min, di[1])
print(r_min - l_max + 1)

Submission status: Wrong Answer

Solution code:
def solve(n, m, LR):
    maxl = 0
    minr = n
    for l, r in LR:
        if maxl < l:
            maxl = l
        if minr > r:
            minr = r
    return minr - maxl + 1

_n, _m = map(int, input().split())
_LR = [list(map(int, input().split())) for _ in range(_m)]
print(solve(_n, _m, _LR))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L = [0 for _ in range(M)]
R = [0 for _ in range(M)]
for i in range(M):
    L[i], R[i] = map(int, input().split())

l = max(L)
r = min(R)
print(r - l + 1)

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

(N, M) = [int(n) for n in input().split()]

minC = 1
maxC = N
for i in range(M):
    (L, R) = [int(n) for n in input().split()]
    if minC <= maxC:
        minC = max(minC, L)
        maxC = min(maxC, R)

print(maxC - minC + 1)

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

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

L = 1
R = N

for _ in range(M):
	l,r = list(map(int,input().split(' ')))
	L = max(L,l)
	R = min(R,r)

print(R-L+1)

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

(N, M) = [int(n) for n in input().split()]

minC = 1
maxC = N
for i in range(M):
    (L, R) = [int(n) for n in input().split()]
    minC = max(minC, L)
    maxC = min(maxC, R)

print(maxC - minC + 1)

Submission status: Wrong Answer

Solution code:
a, b = list(map(int, input().split()))
v = [list(map(int, input().split())) for n in range(b)]
if b == 1:
  print(a)
elif b % 2 == 0:
  print(2)
else:
  print(1)

Submission status: Wrong Answer

Solution code:
N, M = [int(s) for s in input().split(' ')]
l = 1
r = N
for m in range(M):
    L, R = [int(s) for s in input().split(' ')]
    l = max(l, L)
    r = min(r, R)
print(r - l + 1)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split(' ')))
l = 0
r = 100000
for i in range(m):
    p, q = list(map(int, input().split(' ')))
    l = max(l, p)
    r = min(r, q)
print(r-l + 1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L_list = []
for i in range(M):
    A = list(map(int, input().split()))
    L_list.append(A)
min_range = L_list[0][0]
max_range = L_list[0][1]
for i in range(i, M):
    if L_list[i][0] > min_range:
        min_range = L_list[i][0]
    if L_list[i][1] < max_range:
        max_range = L_list[i][1]
print(max_range-min_range+1) if max_range>=min_range else print(0)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L_list = []
for i in range(M):
    A = list(map(int, input().split()))
    L_list.append(A)
min_range = L_list[0][0]
max_range = L_list[0][1]
for i in range(i, M):
    if L_list[i][0] >= min_range:
        min_range = L_list[i][0]
    if L_list[i][1] <= max_range:
        max_range = L_list[i][1]
print(max_range-min_range+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L_list = []
for i in range(M):
    A = list(map(int, input().split()))
    L_list.append(A)
min_range = L_list[0][0]
max_range = L_list[0][1]
for i in range(i, M):
    if L_list[i][0] > min_range:
        min_range = L_list[i][0]
    if L_list[i][1] < max_range:
        max_range = L_list[i][1]
print(max_range-min_range+1)

Submission status: Wrong Answer

Solution code:
l = input().split(" ")
n = int(l[0])
m = int(l[1])

r = []
l = []

for i in range(m):
    gatei = input().split(" ")
    li = int(gatei[0])
    ri = int(gatei[1])
    l.append(li)
    r.append(ri)

l.sort()
r.sort()

count = r[0] - l[m-1] + 1
print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

s = [0] * (n+2)

for i in range(m):
  l, r = map(int, input().split())
  s[l] += 1
  s[r+1] -= 1

ans = [0] * (n+2)
for i in range(1, n+2):
  ans[i] = ans[i-1] + s[i]

print(ans.count(max(ans)))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

s = [0] * (n+2)

for i in range(m):
  l, r = map(int, input().split())
  s[l-1] += 1
  s[r] -= 1

ans = [0] * (n+2)
for i in range(1, n+2):
  ans[i] = ans[i-1] + s[i]

print(ans.count(max(ans)))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

s = [0] * (n+1)

for i in range(m):
  l, r = map(int, input().split())
  s[l-1] += 1
  s[r] -= 1

ans = [0] * (n+2)
for i in range(n+1):
  ans[i+1] = ans[i] + s[i]

print(ans.count(max(ans)))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L_list = []
R_list = []
for i 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)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l,r = [0]*m,[0]*m
for i in range(0,m):
    l[i],r[i] = map(int,input().split())
print(min(r) - max(l) + 1)

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
li = [list(map(int, input().split())) for i in range(M)]

count = 0

mi = 0
ma = 10**9

for index, n in enumerate(li):
  if mi < n[0]:
    mi = n[0]

  if ma > n[1]:
    ma = n[1]

ans = N - (mi - 1) - (N - ma)

print(ans)

Submission status: Wrong Answer

Solution code:
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())

l = max(L)
r = min(R)

print(r-l+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(' '))
l_val, r_val = map(int, input().split(' '))
for i in range(M-1):
    l, r = map(int, input().split(' '))
    l_val = max(l_val, l)
    r_val = min(r_val, r)
if r_val == l_val:
    print(1)
else:
    print(r_val - l_val + 1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(' '))
l_val, r_val = map(int, input().split(' '))
for i in range(M-1):
    l, r = map(int, input().split(' '))
    l_val = max(l_val, l)
    r_val = min(r_val, r)

print(r_val - l_val + 1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
left = 0 # 制約における最小を超える値
right = 10 ** 6 # 制約における最大を超える値
cards = []
for _ in range(m):
  l, r = map(int, input().split())
  if left < l:
    left = l
  if r < right:
    right = r
  cards += [l, r]

print(len(list(filter(lambda x : left <= x and x <= right, cards))))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
MIN = 0
MAX = 10**5
for i in range(m):
    l,r = map(int,input().split())
    MIN = MIN if MIN > l else l
    MAX = MAX if MAX < r else r
print(MAX-MIN+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
MIN = 0
MAX = 10**5
for i in range(m):
    l,r = map(int,input().split())
    MIN = MIN if MIN > l else l
    MAX = MAX if MAX < r else r
if MIN > n:
    print(0)
else:
    MAX = MAX if MAX <= n else n
    print(MAX-MIN+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
L=[0]*m
R=[0]*m
ans=0
for i in range(m):
        L[i],R[i]=map(int,input().split())
        for j in range(L[i],R[i]):
            if(j==m):
                ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(M)]

for e in l:
  L,R = e[0],e[1]
  if e == l[0]:
    _L,_R = L,R
  else:
    if _L < L:
      _L = L
    if _R > R:
      _R = R
print(_R - _L + 1)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
N, M= map(int, input().split())

L,R = 0,100100
ans = [0]*(N+1)
for i in range(M):
    a,b = map(int,input().split())
    L = max(L,a)
    R = min(R,b)
print(R-L+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ll=[list(map(int,input().split())) for i in range(m)]

a=0
b=n
for l,r in ll:
 a=max(a,l)
 b=min(b,r)
print(b-a+1)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
Lmax=1
Rmin=N
for i in range(M):
    L,R=map(int,input().split())
    Lmax=max(Lmax,L)
    Rmin=min(Rmin,R)
    
print(Rmin-Lmax+1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

n,m=map(int, input().split())
l = ["" for _ in range(m)]
r = ["" for _ in range(m)]

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

x = len(range(max(l), min(r)))+1
print(x)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
a=0
z=10**5
for i in range(m):
    a=max(a,l[i][0])
    z=min(z,l[i][1])
print(z-a+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
print(l)
a=0
z=10**5
for i in range(m):
    a=max(a,l[i][0])
    z=min(z,l[i][1])
print(z-a+1)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    _, m = map(int, input().split())

    max = -1
    min = 10 ** 5 + 1
    for _ in range(m):
        l, r = map(int, input().split())
        if l > max:
            max = l
        if r < min:
            min = r
    print(min - max + 1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, m = map(int, input().split())

    a = [1, n]
    for i in range(m):
        l, r = map(int, input().split())
        res = [max(a[0], l), min(a[1], r)]
    print(max(0, a[1]-a[0]+1))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l, r = 1, n

for _ in range(m):
    tmpL, tmpR = map(int, input().split())
    l = max(l, tmpL)
    r = min(r, tmpR)

print(r - l + 1)

Submission status: Wrong Answer

Solution code:
_, M = map(int, input().split())
left_rights = [list(map(int, input().split())) for _ in range(M)]

l_max = 0
r_min = 10 ** 6
for l, r in left_rights:
    l_max = max(l_max, l)
    r_min = min(r_min, r)

print(r_min - l_max + 1)

Submission status: Wrong Answer

Solution code:
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)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
l,r=map(int, input().split())
l_max=l
r_min=r
for i in range(M-1):
  l,r=map(int, input().split())
  if l_max<l:
    l_max=l
  if r_min>r:
    r_min=r
print(r_min-l_max+1)

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
list_lr=[list(map(int, input().split())) for _ in range(M)]
a=list_lr[0][1]-list_lr[-1][0]+1
print(a if a<=N else N)

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
list_lr=[list(map(int, input().split())) for _ in range(M)]
print(list_lr[0][1]-list_lr[-1][0]+1)

Submission status: Wrong Answer

Solution code:
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()

Submission status: Wrong Answer

Solution code:
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)
    print(right - left + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

mxa = 0
mnb = n

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

if mxa > mnb:
    ans = 0
else:
    ans = mnb - mxa

print(ans+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
rg = []
for i in range(m):
    rg.append(list(map(int, input().split())))

ans = set(range(0, n))
for i in rg:
    ans &= set(range(i[0], i[1]))

print(len(ans)+1)

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
pass_id = [i for i in range(1, N+1)]

for i in range(M):
    L,R=map(int, input().split())
    for id in pass_id:
        if not id in range(L,R+1):
            pass_id.pop(pass_id.index(id))
print(len(pass_id))

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
l,r = [0]*m,[0]*m
for i in range(m):
    l[i],r[i] = map(int,input().split())
s = min(n,min(r)) - min(n,max(l))
if (n < max(l)):
    s = 0
else:
    s += 1
print(s)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
l,r = [0]*m,[0]*m
for i in range(m):
    l[i],r[i] = map(int,input().split())
s = min(n,min(r)) - min(n,max(l))
if (n < min(r)):
    s = 0
else:
    s += 1
print(s)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
l,r = [0]*m,[0]*m
for i in range(m):
    l[i],r[i] = map(int,input().split())
s = min(n,min(r)) - min(n,max(l))
print(s+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
left,right = map(int,input().split())
for i in range(m-1):
    a,b = map(int,input().split())
    left = max(left,a)
    right = min(right,b)
print(right-left+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
idcard = [[int(j) for j in input().split()] for i in range(M)]

L = 0
R = 10**10
for i in idcard:
    L = max(L, i[0])
    R = min(R, i[1])

print(R-L+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
idcard = [[int(j) for j in input().split()] for i in range(M)]
for i in range(1,M):
    idcard[i] = [idcard[i][0], idcard[i-1][1]]
    
print(idcard[M-1][1]-idcard[M-1][0] + 1)

Submission status: Wrong Answer

Solution code:
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())
print(min(R)-max(L)+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
lr = []

for i in range(m):
    lr.append(list(map(int, input().split())))

lmax = 0
mmin = 10**5

for i in range(m):
    lmax = max(lmax, lr[i][0])
    mmin = min(mmin, lr[i][1])

print(mmin - lmax + 1)