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:
def myAnswer(N,M,L,R) -> int:
   total = 0
   MAXL=max(L)
   MINR =min(R)
   return MINR - MAXL + 1


def modelAnswer():
   tmp=1
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)
   print(myAnswer(N,M,L[:],R[:]))
   

if __name__ == '__main__':
   main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    ll = []
    rl = []
    n,m = map(int,input().split())
    for _ in range(m):
        l,r = map(int, input().split())
        ll.append(l)
        rl.append(r)
    l = max(ll)
    r = min(rl)
    print(r-l+1)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
d = [0]*(10**5)
l, r = map(int, input().split())
for _ in range(1, 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 = map(int, input().split())

left = 0
right = 10000

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

result = right - left + 1

print(result if result >= 0 else 0)

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().strip().split()]
a = []
for _ in range(m):
    a.append([int(i) for i in input().strip().split()])
a.sort(key=lambda s: s[1])
result = a[0]
for i in range(1, len(a)):
    if result[1] >= a[i][0]:
        result = [max(result[0], a[i][0]), min(result[1], a[i][1])]
    else:
        result = []
        break
print(len(set(result)))

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().strip().split()]
a = []
for _ in range(m):
    a.append([int(i) for i in input().strip().split()])
a.sort(key=lambda s: s[1])
result = a[0]
for i in range(1, len(a)):
    if result[1] >= a[i][0]:
        result = [max(result[0], a[i][0]), min(result[1], a[i][1])]
    else:
        result = []
        break
print(len(result))

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().strip().split()]
a = []
for _ in range(m):
    a.append([int(i) for i in input().strip().split()])
a.sort(key=lambda s: s[1])
tmp = a[0]
for i in a[1:]:
    if tmp[1] >= i[0]:
        tmp = [max(tmp[0], i[0]), min(tmp[1], i[1])]
print(tmp[1] - tmp[0] + 1)

Submission status: Wrong Answer

Solution code:
# indeednow_A_b
import sys
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
L = [0 for i in range(M)]
R = [0 for i in range(M)]
for i in range(M):
    L[i], R[i] = [int(x) for x in stdin.readline().rstrip().split()]
# print(L, R)
ans = set()
ans1 = 0
ans2 = 10**6
for k in range(M):
    if ans1 < L[k]:
        ans1 = L[k]
    if ans2 > R[k]:
        ans2 = R[k]
    # temp = set()
    # for l in range(L[k], R[k]+1):
    #     temp.add(l)
    # if len(ans) != 0:
    #     ans = temp & ans
    # else:
    #     ans = temp
print(ans2+1-ans1)

Submission status: Wrong Answer

Solution code:
n, m = (int(x) for x in input().split())
l, r = (int(x) for x in input().split())
sss = set(range(l, r + 1))
for i in range(m-1):
  l, r = (int(x) for x in input().split())
  sss &= set(range(l, r))
print(len(sss))

Submission status: Wrong Answer

Solution code:
N,M= list(map(int,input().split()))
end = []
start = []
for i in range(M):
    A,B = list(map(int,input().split()))
    end.append(B)
    start.append(A)
print(min(end) - max(start)+1)

Submission status: Wrong Answer

Solution code:
N,M= list(map(int,input().split()))
list_A = [0] * N
for i in range(M):
    A,B = list(map(int,input().split()))
    list_A[A:B+1] = map(lambda x: x+1,list_A[A:B+1])
print(list_A.count(M))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    import sys

    input = sys.stdin.readline

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

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


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

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())

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

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

Submission status: Wrong Answer

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

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

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):
    tmpa, tmpb = map(int, input().split())
    l.append(tmpa)
    r.append(tmpb)

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

Submission status: Wrong Answer

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

left, right = map(int, input().split())
for _ in range(M-1):
    L, R = map(int, input().split())
    left = max(left, L)
    right = min(right, R)
print(right - left + 1)

Submission status: Wrong Answer

Solution code:
# Problem C - Prison

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

# initialization
max_left = 0
min_right = N

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

# output
ans = min_right - max_left + 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)]

lr.sort(reverse = True)
ansl = lr[0][0]
ansr = 10**9
for i in range(m):
    r = lr[i][1]
    if r < ansl:
        ansr = min(ansr,r)
ans = max(0,ansr-ansl+1)

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l0, r0 = map(int, input().split())
for j in range(1, m):
    l1, r1 = map(int, input().split())
    l0 = max(l0, l1)
    r0 = min(r0, r1)
print(r0 - l0 + 1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l0, r0 = 0, n+1
for j in range(m):
    l1, r1 = map(int, input().split())
    l0 = max(l0, l1)
    r0 = min(r0, r1)
print(r0 - l0 + 1)

Submission status: Wrong Answer

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

lr.sort(reverse = True)
ansl = lr[0][0]
ansr = 10**9
for i in range(m):
    r = lr[i][1]
    if r >= ansl:
        ansr = min(ansr,r)
ans = max(0,ansr-ansl+1)

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l0, r0 = 1, n
for j in range(m):
    l1, r1 = map(int, input().split())
    l0 = max(l0, l1)
    r0 = min(r0, r1)
print(r0-l0+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ans = [i+1 for i in range(n)]
l = []
r = []
for i in range(m):
    l1,r1 = map(int,input().split())
    l.append(l1)
    r.append(r1)
    
left = max(l)
right = min(r)
print(len(ans[left:right+1]))

Submission status: Wrong Answer

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

lr.sort(reverse = True)
ansl = lr[0][0]
ansr = 10**9
for i in range(m):
    r = lr[i][1]
    if r >= ansl:
        ansr = min(ansr,r)
ans = ansr-ansl+1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = 1
r = 10 ** 5
for _ in range(m):
    li, ri = map(int, input().split())
    l = max(l, li)
    r = min(r, ri)

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = 1
r = m
for _ in range(m):
    li, ri = map(int, input().split())
    l = max(l, li)
    r = min(r, ri)

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = 1
r = n
for _ in range(m):
    li, ri = map(int, input().split())
    l = max(l, li)
    r = min(r, ri)

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

Submission status: Wrong Answer

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

L = 1
R = N
for i in range(M):
    a, b = LR[i]
    L = max(L,a)
    R = min(R,b)
print(R-L+1)

Submission status: Wrong Answer

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

max_L = 0
min_R = float("inf")
for i in range(m):
    L, R = LR[i]
    max_L = max(max_L, L)
    min_R = min(min_R, R)
print(min_R - max_L + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = 1
r = n
for _ in range(m):
    li, ri = map(int, input().split())
    l = max(l, li)
    r = min(r, ri)
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 if min(R)-max(L) > 0 else 0)

Submission status: Wrong Answer

Solution code:
def resolve():
    n, m = map(int, input().split())
    for i in range(m):
        l, r = map(int, input().split())
        if i == 0:
            start = l
            end = r
        else:
            if start <= l:
                start = l
            if r <= end:
                end = r
    print(end-start+1)
resolve()

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())
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())
table = [[int(i) for i in input().split()] for _ in range(M)]

ans = [table[0][0], table[0][1]]
cnt = 0

for i in table[1:]:
    if ans[0] <= i[0] <= ans[1]:
        ans[0] = i[0]
    if ans[0] <= i[1] <= ans[1]:
        ans[1] = i[1]
    if ans[1] <= i[0] or i[1] <= ans[0]:
        cnt += 1
        break

if cnt != 0:
    print(0)
else:
    print(ans[1] - ans[0] + 1)

Submission status: Wrong Answer

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

ans = [table[0][0], table[0][1]]
cnt = 0

for i in table[1:]:
    if ans[0] <= i[0] <= ans[1]:
        ans[0] = i[0]
    if ans[0] <= i[1] <= ans[1]:
        ans[1] = i[1]
    if ans[1] < i[0] or i[0] < ans[0]:
        cnt += 1
        break

if cnt != 0:
    print(0)
else:
    print(ans[1] - ans[0] + 1)

Submission status: Wrong Answer

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

ans = [0, 100000]

for i in table:
    if i[0] >= ans[0]:
        ans[0] = i[0]

    if i[1] <= ans[1]:
        ans[1] = i[1]

print(ans[1] - ans[0] + 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(1 - max(L) + min(R) if max(L) < min(R) else 0)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L = [i for i in range(1,N+1)]
a,b = map(int,input().split())
for i in range(M-1):
    c,d = map(int,input().split())
    a = max(a,c)
    b = min(b,d)
print(b-a+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)-min(L)+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lList = [arr[0] for arr in LR]
rList = [arr[1] for arr in LR]

l = max(lList)
r = min(rList)

print(r-l+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l = list(list(map(int,input().split())) for _ in range (m))
a = l[0][0]
b = l[0][1]
for s,t in l:
  a = max(a,s)
  b = min(b,t)
print(b-a+1)

Submission status: Wrong Answer

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

for n 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:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
L = 0; R = 10 ** 6
for _ in range(M):
    l, r = lr()
    if l > L:
        L = l
    if r < R:
        R = r

answer = R - L + 1
print(answer)

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)
left = max(l)
right = min(r)

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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = []
lmax = 0
rmin = 10**6
for i in range(m):
    a.append(list(map(int,input().split())))
    if a[i][0] > lmax:
        lmax = a[i][0]
    if a[i][1] < rmin:
        rmin = a[i][1]
print(1+rmin-lmax)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
left = 1
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:
_, __, *d = map(int, open(0).read().split())
print(min(d[1::2]) - max(d[::2]) + 1)

Submission status: Wrong Answer

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

for k in range(m):
  i,r = map(int,input().split())
  
  i_now.append(i)
  r_now.append(r)

i_max = max(i_now)
r_min = min(r_now)

ans = r_min - i_max + 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
i_now = 0
r_now = 10**5 + 1

for k in range(m):
  i,r = map(int,input().split())
  if i_now < i:
    i_now = i

  if r_now > r:
    r_now = r
    
if n < r_now:
  r_now = n
  
  
ans = r_now - i_now + 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
i_now = 0
r_now = 10**5 + 1

for k in range(m):
  i,r = map(int,input().split())
  if i_now < i:
    i_now = i

  if r_now > r:
    r_now = r
    
if n < r:
  r_now = n
  
ans = r_now - i_now + 1
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
left=0
right=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)
count=0
for i in range(1,N+1):
  if max(L)<=i<=min(R):
    count+=1
  else:
    break
print(count)

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)
count=0
for i in range(1,N+1):
  if min(L)>i or i>max(R):
    break
  else:
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
#C
n, m = map(int, input().split())
l = []
r = []
for i in range(m):
    lin = list(map(int, input().split()))
    l.append(lin[0])
    r.append(lin[1])
lma = max(l)
rmi = min(r)
print(rmi - lma + 1)

Submission status: Wrong Answer

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

maxi = 10**6
mini = 0
for lr in LR:
    mini = max(lr[0],mini)
    maxi = min(lr[1],maxi)

if maxi <= N:
    print(maxi-mini+1)
else:
    print(N-maxi+1)

Submission status: Wrong Answer

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

maxi = 0
mini = 10**6
for lr in LR:
    maxi = max(lr[0],maxi)
    mini = min(lr[1],mini)

if mini-maxi+1 >= N:
    print(N)
else:
    print(mini-maxi+1)

Submission status: Wrong Answer

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

maxi = 0
mini = 10**6
for lr in LR:
    maxi = max(lr[0],maxi)
    mini = min(lr[1],mini)

print(mini-maxi+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
left, right = map(int, input().split())
for _ in range(M-1):
    c_left, c_right = map(int, input().split())
    if c_left > left:
        left = c_left
    if c_right < right:
        right = c_right

print(right-left+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
array = [list(map(int, input().split())) for i in range(m)]
result = [1, n]
for el in array:
    work = sorted(result + el)
    result = [work[1], work[2]]
    if result[0] > result[1]:
        result = [1, 0]
        break
print(result[1]-result[0]+1)

Submission status: Wrong Answer

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

LM = 0
RM = N+1

for i in range(M):
  L, R = map(int, input().split())
  if L > LM:
    LM = L
  
  if R < RM:
    RM = R

print(N-(LM-1)-(N-RM))

Submission status: Wrong Answer

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

for m in range(M):
  L2,R2 = map(int,input().split())
  L1 = min(L1,L2)
  R1 = max(R1,R2)
  
print(max(0,R1-L1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(m):
  f,g=map(int,input().split())
  a.append(f)
  b.append(g)
  
print(min(b)-max(a)+1)

Submission status: Wrong Answer

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

for i in range(m-1):
  a, b = map(int,input().split())
  if a > l:
    l = a
  if b < r:
    r = b

print(r-l+1)

Submission status: Wrong Answer

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


#card_list = np.zeros(n)

under = 1
top = n

for i in range(m):
    l, r = map(int, input().split())
    if under < l:
        under = l
    if top > r:
        top = r

#print(under, top)

print(top-under+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
left = 1
right = N
for _ in range(M):
  L, R = [int(i) for i in input().split()]
  if left < L:
    left = L
  if right > R:
    right = R
if left < right:
  print(right-left+1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
left = 1
right = N
for _ in range(M):
  L, R = [int(i) for i in input().split()]
  if left < L:
    left = L
  if right > R:
    right = R
if left < right:
  print(right-left+1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
left = 0
right = N - 1
for _ in range(M):
  L, R = [int(i) for i in input().split()]
  if left < L:
    left = L
  if right > R:
    right = R
print(right-left+1)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
left = 0
right = N - 1
for _ in range(M):
  L, R = [int(i) for i in input().split()]
  if left < L:
    left = L
  if right > R:
    print(right, R)
    right = R
print(right-left+1)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
left = 0
right = N
for _ in range(M):
  L, R = [int(i) for i in input().split()]
  if left < L:
    left = L
  if right > R:
    right = R
print(R-L+1)

Submission status: Wrong Answer

Solution code:
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    l = -1
    r = 10**20
    for _ in range(m):
        a,b = map(int, input().split())
        l = max(l, a)
        r = min(r, b)
    print(r-l+1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
left,right = 0,N
for i in range(M):
    L,R = map(int,input().split())
    if(left<L):
        left = L
    if(R<right):
        right = R
print(right-left+1)

Submission status: Wrong Answer

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

ans = [0, 10**6]

for i in range(M):
    ans[0] = max(ans[0], L[i][0])
    ans[1] = min(ans[1], L[i][1])

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def mi():
    return map(int, input().split())
'''
3 4
*G*S
G**S
*G*S
'''
n,m = mi()
l = -1
r = 1e10
for i in range(m):
    a,b=mi()
    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=1;ma=n
te=set(range(1,n+1))
for i in range(m):
    x,y=map(int,input().split())
    l=max(x,l)
    ma=min(ma,y)
print(min(abs(l-ma)+1,m))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=1;ma=n
te=set(range(1,n+1))
for i in range(m):
    x,y=map(int,input().split())
    l=max(x,l)
    ma=min(ma,y)
    
print(abs(l-ma)+1)

Submission status: Wrong Answer

Solution code:
x=list(map(int, input().split()))
a=1
b=x[0]
for i in range(x[1]):
	c,d=list(map(int, input().split()))
	if a<c:
		a=c
	if b>d:
		b=d

if b-a>0:
	print(b-a+1)
else:
	print(0)

Submission status: Wrong Answer

Solution code:
n, m=map(int, input().split())
lst=[None]*m
for i in range(m):
    lst[i]=tuple(map(int, input().split()))

left=max([el[0] for el in lst])
right=min([el[1] for el in lst])
print(right-left+1)

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())
li = [list(map(int,input().split())) for _ in range(m)]
maxl = max(li, key=lambda x:x[0])[0]
minr = min(li, key=lambda x:x[1])[1]
if n < maxl or maxl >= minr:
    print(0)
elif maxl <= n <= minr:
    print(n-maxl+1)
else:
    print(minr-maxl+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(m)]
maxl = max(li, key=lambda x:x[0])[0]
minr = min(li, key=lambda x:x[1])[1]
if n < maxl:
    print(0)
elif maxl <= n <= minr:
    print(n-maxl+1)
else:
    print(minr-maxl+1)

Submission status: Wrong Answer

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

s = [0] * (N + 1)
for i in range(M):
    l, r = lr[i]
    s[l - 1] += 1
    if r != N + 2:
        s[r] -= 1

ruiseki = [0] * (N + 1)
for i in range(1, N + 1):
    ruiseki[i] += ruiseki[i - 1] + s[i]

#max_ = max(ruiseki)
print(ruiseki.count(M))

Submission status: Wrong Answer

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

s = [0] * (N + 1)
for i in range(M):
    l, r = lr[i]
    s[l - 1] += 1
    if r != N + 2:
        s[r] -= 1

ruiseki = [0] * (N + 1)
for i in range(1, N + 1):
    ruiseki[i] += ruiseki[i - 1] + s[i]

max_ = max(ruiseki)
print(ruiseki.count(max_))

Submission status: Wrong Answer

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

s = [0] * (N + 1)
for i in range(M):
    l, r = lr[i]
    s[l] += 1
    if r + 1 != N + 1:
        s[r + 1] -= 1

ruiseki = [0] * (N + 1)
for i in range(1, N + 1):
    ruiseki[i] += ruiseki[i - 1] + s[i]

max_ = max(ruiseki)
print(ruiseki.count(max_))

Submission status: Wrong Answer

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

l,r=1,N

for _ 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 = map(int,input().split())
#L = list(map(int,input().split()))
li = [0]*n
print(li)
for i in range(m):
    a,b = (map(int,input().split()))
    print(a,b)
    for j in range(a-1,b):
        li[j] += 1
print(li.count(m))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
lr_list = [list(map(int, input().split())) for _ in range(m)]
left = 0
right = 10 ** 10
for l, r in lr_list:
    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)
L1 = max(l)
R1 = min(r)
if R1 > L1:
    print(R1 - L1 + 1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def solve():
    N, M = map(int, input().split())
    
    c = 0
    l = 0
    r = 10 ** 9
    for _ in range(M):
        a, b = list(map(int, input().split()))
        l = max(l, a)
        r = min(r, b)
    
    if N < l:
        return 0
    elif N == l:
        return 1
    elif l < N < r:
        return N-l+1
    else:
        return r-l+1

print(solve())

Submission status: Wrong Answer

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n,m = map(int,input().split())
# 列ベクトルとかの受け取り
lists = [list(map(int,input().split())) for _ in range(m)]

maxL = 1
minR = n
for i in range(m):
    maxL = max(maxL,lists[i][0])
    minR = min(minR,lists[i][1])

ans = minR - maxL +1
print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

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)
    
L_max = max(L_list)
R_min = min(R_list)

print(R_min - L_max + 1)