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:
# -*- coding utf-8 -*-

# TLE
# N, M = map(int, input().split())
# LR = [list(map(int, input().split())) for _ in range(M)]

# ids = [1] * N
# for i in range(M):
#     ids[:LR[i][0]-1] = [0] * len(ids[:LR[i][0]-1])
#     ids[(LR[i][1]):] = [0] * len(ids[(LR[i][1]):])

# print(sum(ids))

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

min_L, max_L, min_R, max_R = N+1, 0, N+1, 0
for i in range(M):
    L, R = map(int, input().split())
    min_L = min(min_L, L)
    max_L = max(max_L, L)
    min_R = min(min_R, R)
    max_R = max(max_R, R)

print(min_R - (max_L - 1))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N,M=map(int,input().split())
L = [0]*(N+1)
for _ in range(M):
  l,r = map(lambda x:int(x)-1,input().split())
  L[l]+=1
  L[r+1]+=1

L = list(accumulate(L))
print(min(N,L.count(M)))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N,M=map(int,input().split())
L = [0]*(N+1)
for _ in range(M):
  l,r = map(lambda x:int(x)-1,input().split())
  L[l]+=1
  L[r+1]+=1

L = list(accumulate(L))
print(L.count(M))

Submission status: Wrong Answer

Solution code:
import sys
N,M = map(int,input().split())
L,R = sorted(map(int, input().split()))
range_min = L
range_max = R
print(L,R)

def end_checker(L,R,range_min,range_max):
  if  L > range_max or R < range_min:
    return True
  return False

while M > 1:
  L,R = sorted(map(int, input().split()))
  if end_checker(L,R,range_min,range_max):
    print(0)
    sys.exit()
  
  range_min = L if L > range_min else range_min
  range_max = R if R < range_max else range_max
  print(range_max,range_min)
  M -= 1

ans = range_max - range_min + 1  
print(ans)

Submission status: Wrong Answer

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

    # print(L)
    # print(R)
    Lout = max(L)
    Rout = min(R)
    print(Rout - Lout+1)
    # num = 0
    # for j in range(1, N+1):
    #     plus = 1
    #     # print(j)
    #     if plus == 1:
    #         for i in range(0, len(box), 2):
    #             # print(box[i], box[i+1])
    #             if j < box[i] or box[i+1] < j:
    #                 plus = 0
    #                 break

    #         num += plus

    # print(num)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
N,M = map(int,input().split())
L,R = sorted(map(int, input().split()))
range_min = L
range_max = R


def end_checker(L,R,range_min,range_max):
  if  L < range_max or R < range_min:
    return True
  return False

while M > 1:
  L,R = sorted(map(int, input().split()))
  if end_checker(L,R,range_min,range_max):
    print(0)
    sys.exit()
  
  range_min = L if L > range_min else range_min
  range_max = R if R < range_max else range_max
  M -= 1

ans = range_max - range_min + 1  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N,M = map(int,input().split())
L,R = sorted(map(int, input().split()))
range_min = L
range_max = R


def end_checker(L,R,range_min,range_max):
  if  L < range_max or R < range_min:
    return True
  return False

while M > 1:
  L,R = sorted(map(int, input().split()))
  if end_checker(L,R,range_min,range_max):
    print(0)
    sys.exit()
  
  range_min = L if L > range_min else range_min
  range_max = R if R < range_max else range_max
  print(range_max,range_min)
  M -= 1

ans = range_max - range_min + 1  
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L,R = sorted(map(int, input().split()))
range_min = L
range_max = R

while M > 1:
  L,R = sorted(map(int, input().split()))
  range_min = L if L > range_min else range_min
  range_max = R if R < range_max else range_max
  M -= 1

print(range_max - range_min + 1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L,R = sorted(map(int, input().split()))
range_min = L
range_max = R

while M > 1:
  L,R = sorted(map(int, input().split()))
  range_min = L if L > range_min else range_min
  range_max = R if R < range_max else range_max
  print(range_max,range_min)
  M -= 1

print(range_max - range_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)
    
print(min(R) -max(L) +1)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())

cards = np.zeros(n + 1)

for i in range(m):
    left, right = map(int, input().split())
    cards[left - 1] = 1
    cards[right] = -1
print(np.sum(cards.cumsum() >= m))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=0
r=10000000000000
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())
l=0
r=10000000000000
for i in range(m):
  a,b=map(int,input().split())
  l=max(l,a)
  r=min(r,b)
print(l)
print(r)
print(r-l+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=0
r=10^5
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())
for i in range(m):
  l=0
  r=10^5
  a,b=map(int,input().split())
  l=max(l,a)
  r=min(r,b)
print(r-l)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
count = 0
for i in range(M):
    a,b = map(int,input().split())
    if count == 0:
        min = a
        max = b
        count = 1
    else:
        if min < a:
            min =a
        if max > b:
            max = b
if M == i+1:
    print(max-min+1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
count = 0
for i in range(M):
    a,b = map(int,input().split())
    if count == 0:
        min = a
        max = b
        count = 1
    else:
        if min < a:
            min =a
        if max > b:
            max = b
        
print(max-min+1)

Submission status: Wrong Answer

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

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

print(max(lmax - rmin + 1, 0))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m=map(int,input().split())
L=[]
R=[]
for _ in range(m):
  a,b=map(int,input().split())
  L.append(a)
  R.append(b)
count=[0]*n
for i in range(m):
  a=L[i]
  b=R[i]
  for j in range(0,a):
    if a-1==0:
        break
    else:
        count[j]=1
  for j in range(b+1,n):
    count[j]=1
print(count.count(0))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m=map(int,input().split())
L=[]
R=[]
for _ in range(m):
  a,b=map(int,input().split())
  L.append(a)
  R.append(b)
count=[0]*n
for i in range(m):
  a=L[i]
  b=R[i]
  for j in range(0,int(a)):
    count[j]=1
  for j in range(int(b+1),n):
    count[j]=1
print(count.count(0))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
LMax,RMin = 0,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:
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],R[i]=l,r
print(abs(min(R)-max(L))+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,r=map(int,input().split())
    L[i],R[i]=l,r
print(min(R)-max(L)+1)

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

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

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


if min(r) < n:
    print(min(r) - max(l) + 1)
else:
    print(max((n-max(l)+1),0))

Submission status: Wrong Answer

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

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


if min(r) < n:
    print(min(r) - max(l) + 1)
else:
    print(n - max(l) + 1)

Submission status: Wrong Answer

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

for l,r in LR:
    left = max(left,l -1)
    right = min(right,r -1)

if l  > r:
    print(0)
else:
    print( right - left +1)

Submission status: Wrong Answer

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

for l,r in LR:
    left = max(left,l -1)
    right = min(right,r -1)

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
lr=[[int(i) for i in input().split()]for i in range(m)]
li=[0 for i in range(n)]
for l,r in lr:
    for i in range(l,r+1):
        li[i-1]+=1
ans=0

memo=max(li)
p=li.index(memo)

for i in range(n):
    if li[i]==memo:
        if i==p:
            ans+=1
            p+=1
        else:
            ans=0
            break
print(ans)

Submission status: Wrong Answer

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

Lmax = 0
Rmin = 10**5 + 1

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

    Lmax = max(Lmax,L)
    Rmin = min(Rmin,R)

print(int(Rmin - Lmax + 1))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
cnt = 0
id = []
for _ in range(m):
        l= list(map(int, input().split()))
        if len(id) == 0:
                id = l
        else:
                if id[0] < l[0]:
                        id[0] = l[0]
                elif id[1] > l[1]:
                        id[1] = l[1]
print(id)
if id[1] < id[0]:
        cnt = 0
else:
        cnt = id[1]-id[0]+1
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
id = []
for _ in range(m):
        l= list(map(int, input().split()))
        if len(id) == 0:
                id = l
        else:
                if id[0] < l[0]:
                        id[0] = l[0]
                if id[1] > l[1]:
                        id[1] = l[1]
cnt = id[1]-id[0]+1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

n,m = map(int, sys.stdin.readline().split())
less,more = 0,n

for i in range(m):
    l,r = map(int, sys.stdin.readline().split())
    less = max(less, l)
    more = min(more, r)

print 1+more-less

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
gates = []
for i in range(m):
    gates.append(list(map(int, input().split())))
candidate = [1, n]
for gate in gates:
    if candidate[0] < gate[0]:
        candidate[0] = gate[0]
    if gate[1] < candidate[1]:
        candidate[1] = gate[1]
if candidate[1] <= candidate[0]:
    print(0)
else:
    print(candidate[1] - candidate[0] + 1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
gates = []
for i in range(m):
    gates.append(list(map(int, input().split())))
candidate = [1, n]
for gate in gates:
    if candidate[0] < gate[0]:
        candidate[0] = gate[0]
    if gate[1] < candidate[1]:
        candidate[1] = gate[1]
if candidate[1] == candidate[0]:
    print(0)
else:
    print(candidate[1] - candidate[0] + 1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
gates = []
for i in range(m):
    gates.append(list(map(int, input().split())))
candidate = [1, n]
for gate in gates:
    if candidate[0] < gate[0]:
        candidate[0] = gate[0]
    if gate[1] < candidate[1]:
        candidate[1] = gate[1]

print(candidate[1] - candidate[0] + 1)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
L=0
R=10000
for i in range(M):
  l,r=map(int,input().split())
  L=max(L,l)
  R=min(r,R)
if L>R :
  print(0)
else :
  print(R-L+1)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
L=0
R=10000
for i in range(M):
  l,r=map(int,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 = []
R = []

for m in range(M):
    L_in, R_in = list(map(int, input().split()))
    L.append(L_in)
    R.append(R_in)

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

Submission status: Wrong Answer

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

l = -1
r = n+1
for i in range(m):
  l = max(l,gate[i][0])
  r = min(r,gate[i][1])
print(r-l + (r != l))

Submission status: Wrong Answer

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

l = -1
r = n+1
for i in range(m):
  l = max(l,gate[i][0])
  r = min(r,gate[i][1])
print(r-l+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
mir = n
mal = 0
for _ in range(m):
  l,r = map(int,input().split())
  if l > mal:
    mal = l
  if r < mir:
    mir = r
print(0 if mir-mal <= 0 else (mir-mal)+1)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
lr = [list(map(int, input().split())) for i in range(m)]
lr.sort()
r_min = 100000
l_max = 0
lr_min = 100000

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

lr_min = [r_min - l_max + 1 if l_max < r_min else 0]
print(lr_min[0])

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
lr = [list(map(int, input().split())) for i in range(m)]
lr.sort()
r_min = 100000
l_max = 0
lr_min = 100000

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

lr_min = r_min - l_max + 1

print(lr_min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
lr = [list(map(int, input().split())) for i in range(m)]
lr.sort()
lr_min = 100000
lr_difference = 0

for i in range(m - 1):
    if max(lr[0]) >= min(lr[i + 1]):
        lr_difference = max(lr[0]) - min(lr[i + 1]) + 1
        if max(lr[i + 1]) < max(lr[0]):
            lr_difference += max(lr[i + 1]) - max(lr[0])
    else:
        lr_min = 0
        break
    lr_min = min(lr_difference, lr_min)

print(lr_min)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
lr = [list(map(int, input().split())) for i in range(m)]
lr.sort()
lr_min = 100000
lr_difference = 0

for i in range(m - 1):
    if max(lr[0]) >= min(lr[i + 1]):
        lr_difference = max(lr[0]) - min(lr[i + 1]) + 1
        print(lr_difference)
        if max(lr[i + 1]) < max(lr[0]):
            lr_difference += max(lr[i + 1]) - max(lr[0])
    else:
        lr_min = 0
        break
    lr_min = min(lr_difference, lr_min)

print(lr_min)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
lr = [list(map(int, input().split())) for i in range(m)]
lr.sort()
lr_min = 100000
lr_difference = 0

for i in range(m - 1):
    if max(lr[i]) >= min(lr[i + 1]):
        lr_difference = max(lr[i]) - min(lr[i + 1]) + 1
        if max(lr[i + 1]) < max(lr[i]):
            lr_difference += min(lr[i + 1]) - max(lr[i])
    else:
        lr_min = 0
        break
    lr_min = min(lr_difference, lr_min)

print(lr_min)

Submission status: Wrong Answer

Solution code:
import copy

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

lr = [list(map(int, input().split())) for i in range(m)]
lr.sort()
lr_min = 100000
lr_difference = 0

for i in range(m - 1):
    if max(lr[i]) >= min(lr[i + 1]):
        lr_difference = max(lr[i]) - min(lr[i + 1]) + 1
        print(lr_difference)
        if min(lr[i + 1]) < max(lr[i]):
            lr_difference += min(lr[i + 1]) - max(lr[i])
    else:
        lr_min = 0
        break
    lr_min = min(lr_difference, lr_min)

print(lr_min)

Submission status: Wrong Answer

Solution code:
import copy

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

lr = [list(map(int, input().split())) for i in range(m)]
lr.sort()
print(lr)
lr_min = 100000
lr_difference = 0

for i in range(m - 1):
    if max(lr[i]) >= min(lr[i + 1]):
        lr_difference = max(lr[i]) - min(lr[i + 1]) + 1
        print(lr_difference)
        if min(lr[i + 1]) < max(lr[i]):
            lr_difference += min(lr[i + 1]) - max(lr[i])
    else:
        lr_min = 0
        break
    lr_min = min(lr_difference, lr_min)

print(lr_min)

Submission status: Wrong Answer

Solution code:
import copy

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

lr = [list(map(int, input().split())) for i in range(m)]
lr_zero = copy.deepcopy(lr)

for i in range(m):
    lr_zero[i][0] = abs(lr[i][0] - lr[0][0])
    lr_zero[i][1] = abs(lr[i][1] - lr[0][0])

lr_zero_min = 100000
lr_zero_difference = 0

for i in range(m - 1):
    if lr_zero[0][1] >= lr_zero[i + 1][0]:
        lr_zero_difference = lr_zero[0][1] - lr_zero[i + 1][0] + 1
        print(lr_zero_difference)
        if lr_zero[i + 1][1] < lr_zero[0][1]:
            lr_zero_difference += lr_zero[i + 1][1] - lr_zero[0][1]
    else:
        lr_zero_min = 0
        break
    lr_zero_min = min(lr_zero_difference, lr_zero_min)

print(lr_zero_min)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = map(int,input().split())
LR_mat = np.zeros((M,2))
for i in range(M):
  LR_mat[i,:]=list(map(int,input().split()))

a = np.max(LR_mat[:,0],axis=0)
b = np.min(LR_mat[:,1],axis=0)
print(int(b-a+1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def calculate(n, m, id_list):
  result = 0
  for i in range(1, n+1):
    for id_list_index in range(0, m):
      if (i <= id_list[id_list_index][0]) and (i <= id_list[id_list_index][1]) :
        result = result + 1
        break
    
  return result
  
  
import sys

n=0
m=0
id_list=[]
is_arg_ok = False
try:
  n, m  = map(int, input().split())
  for i in range(0, m):
    gate_min, gate_max = map(int, input().split())
    id_list.append([gate_min, gate_max])
  is_arg_ok = True
  
except:
  print('arg error')
  sys.exit(1)

calculated_num = calculate(n, m, id_list)
print(calculated_num)
sys.exit(0)

Submission status: Wrong Answer

Solution code:
nm = [int(i) for i in input().split()]
lr = [[int(i) for i in input().split()] for i in range(nm[1])]


a = [{j for j in range(lr[i][0], lr[0][1]+1)} for i in range(nm[1])]
b = set()
for i in range(len(a)):
    if b == set():
        b = a[i]
    b = b & a[i]
    print(b)
print(len(b))

Submission status: Wrong Answer

Solution code:
nm = [int(i) for i in input().split()]
lr = [[int(i) for i in input().split()] for i in range(nm[1])]


a = [{j for j in range(lr[i][0], lr[0][1]+1)} for i in range(nm[1])]
print(a)
b = set()
for i in range(len(a)):
    if b == set():
        b = a[i]
    b = b & a[i]
    print(b)
print(len(b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lmin = 1
rmax = n
for i in range(m):
    l, r = map(int, input().split())

    if l > lmin:
        lmin = l

    if r < rmax:
        rmax = r

print(rmax - lmin + 1)

Submission status: Wrong Answer

Solution code:
N, M = [int(x) for x in input().split()]

def check(n, LR):
    return 1 if all(l <= n <=r for l, r in LR) else 0

L = 0
R = N
for _ in range(M):
    l, r = [int(x) for x in input().split()]
    if L < l:
        L = l
    if r < R:
        R = r

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

Submission status: Wrong Answer

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

lmin = 0
rmax = n
for i in range(m):
    l, r = map(int, input().split())

    if l > lmin:
        lmin = l

    if r < rmax:
        rmax = r

print(rmax - lmin + 1)

Submission status: Wrong Answer

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


lmin = 0
rmax = n

for i in range(m):
    l = ll[i]
    r = rl[i]
    
    if l > lmin:
        lmin = l

    if r < rmax:
        rmax = r


print(rmax - lmin + 1)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
L = 1
R = 100000
for _ in range(M):
    l, r = [int(i) for i in input().split()]
    L = max(L, l)
    R = min(R, r)
if L >= R:
    print(0)
else:
    print(R-L+1)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
L = 1
R = 100000
for _ in range(M):
    l, r = [int(i) for i in input().split()]
    L = max(L, l)
    R = min(R, r)
if L <= R:
    print(0)
else:
    print(R-L+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    L = 0
    R = 10**5 + 1
    for _ in range(M):
        left, right = map(int, input().split())
        L = max(L, left)
        R = min(R, right)

    return R - L + 1


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(right - left + 1)

Submission status: Wrong Answer

Solution code:
L,M=map(int,input().split())
MAX=0
MIN=10**5
for i in range(M):
  A,B=map(int,input().split())
  MAX=max(MAX,A)
  MIN=min(MIN,B)
  
if MIN<MAX:
  print(0)
print(MIN-MAX+1)

Submission status: Wrong Answer

Solution code:
L,M=map(int,input().split())
MAX=0
MIN=10**5
for i in range(M):
  A,B=map(int,input().split())
  MAX=max(MAX,A)
  MIN=min(MIN,B)
if MIN-MAX+1 <0:
  print(0)
print(MIN-MAX+1)

Submission status: Wrong Answer

Solution code:
L,M=map(int,input().split())
MAX=0
MIN=10**10
for i in range(M):
  A,B=map(int,input().split())
  MAX=max(MAX,A)
  MIN=min(MIN,B)
print(MIN-MAX+1)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int, input().split()))
l_max = 1
r_min = n
for i in range(m):
    l,r = list(map(int, input().split()))
    if l > l_max:
        l_max = l
    if r < r_min:
        r_min = r
print(r-l+1 if r>=l else 0)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
data=[[int(x) for x in input().split()] for m in range(M)]
_min=max([m[0] for m in data])
_max=min([m[1] for m in data])
print(_max-_min+1)

Submission status: Wrong Answer

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

for i in range(m):
    l, r = map(int, input().split())
    if min < l:
        min = l
    if r < max:
        max = r

print(max-min+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
card=[0 for _ in range(n)]
l, r = map(int, input().split())
l-=1
for i in range(m-1):
    li, ri = map(int, input().split())
    li-=1
    if li>r or ri<l:
        l=r
        break
    elif li>=l and ri<=r:
        pass
    elif li<=l and ri>=r:
        l=li; r=ri
    elif li<=r and ri>=r:
        l=li
    elif ri>=l and li<=l:
        r=ri
    else:
        pass
print(r-l)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
card=[0 for _ in range(n)]
l, r = map(int, input().split())
l-=1
for i in range(m-1):
    li, ri = map(int, input().split())
    li-=1
    if li>r or ri<l:
        l=r
        break
    elif li>l and ri<r:
        pass
    elif li<l and ri>r:
        l=li; r=ri
    elif li<r and ri>r:
        l=li
    elif ri>l and li<l:
        r=ri
    else:
        pass
print(r-l)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
card=[0 for _ in range(n)]
l, r = map(int, input().split())
l-=1
for i in range(m-1):
    li, ri = map(int, input().split())
    li-=1
    if li>r or ri<l:
        l=r
        break
    elif li>l and ri<r:
        pass
    elif li<l and ri>r:
        l=li; r=ri
    elif li<r:
        l=li
    elif ri>l:
        r=ri
    else:
        pass
print(r-l)

Submission status: Wrong Answer

Solution code:
n,m,= map(int,input().split())  #n:カード，m:ゲートの数

l = [0]*m
r = [0]*m

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


lmax = max(l)
rmin = min(r)

if (n >= rmin):
    print(rmin-lmax+1)
elif (lmax<=n)and(rmin>n):
    print(n-lmax+1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n,m,= map(int,input().split())  #n:カード，m:ゲートの数

l = [0]*m
r = [0]*m

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


lmax = max(l)
rmin = min(r)

if (n >= rmin):
    print(rmin-lmax+1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
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 maxId - minId <= 0:
    print(0)
else:
    print((maxId - minId) + 1)

Submission status: Wrong Answer

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

print((maxId - minId) + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Lmin = 0
Rmax = N
for i in range(M) :
    L,R = [int(i) for i in input().split()]
    if (Lmin < L) :
        Lmin = L
    
    if (Rmax > R) :
        Rmax = R
    
print(Rmax-Lmin+1)

Submission status: Wrong Answer

Solution code:
import numpy as np

# 初期値を入力

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

A = np.zeros((M, 2))

for i in range(M):
    A[i, 0], A[i, 1] = map(int, input().split())

# メインプログラム

Flag = 0

Length = np.array([A[i, 0], A[i, 1]])

for i in range(M - 1):
    Length[0] = max(Length[0], A[i, 0])
    Length[1] = min(Length[1], A[i, 1])
    if Length[1] < Length[0]:
        Flag = 1


if Flag == 0:
    print(int(Length[1] - Length[0] + 1))
else:
    print("Nan")

Submission status: Wrong Answer

Solution code:
n,m,= map(int,input().split())  #n:カード，m:ゲートの数

l = [0]*m
r = [0]*m

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


lmax = max(l)
rmin = min(r)

LR = [i for i in range(lmax,rmin+1)]


if lmax > n:
    print(0)
elif (lmax <= n) and (n < rmin):
    print(n-lmax+1)
elif rmin <= n:
    print(rmin-lmax+1)

Submission status: Wrong Answer

Solution code:
n,m,= map(int,input().split())  #n:カード，m:ゲートの数

l = [0]*m
r = [0]*m

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


lmax = max(l)
rmin = min(r)

LR = [i for i in range(lmax,rmin+1)]


if lmax + 1 > n :
    print(0)
else:
    print(rmin-lmax+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
L = set()
R = set()
for i in range(m):
    l, r = map(int, input().split())
    L.add(l)
    R.add(r)
num = min(R) - max(L) + 1
print(num)

Submission status: Wrong Answer

Solution code:
def main():
    n, m = [int(x) for x in input().rstrip().split(" ")]
    
    lowest_id = 1
    highest_id = n
    for i in range(m):
        l, r = [int(x) for x in input().rstrip().split(" ")]
        lowest_id = max(lowest_id, l)
        highest_id = min(highest_id, r)
    print(highest_id - lowest_id + 1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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