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:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    lower = 0
    upper = 10000000000
    for i in range(M):
        lower = max(lower, L[i])
        upper = min(upper, R[i])
    print(upper - lower + 1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]" 
    R = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

p = []
q = []

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

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    lower = 0
    upper = N
    for i in range(M):
        lower = max(lower, L[i])
        upper = min(upper, R[i])
    print(upper - lower + 1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]" 
    R = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

min_card = max(l[0] for l in gate_l)
max_card = min(l[1] for l in gate_l)

if max_card > min_card:
    print(max_card - min_card +1)
    
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
a=[int(i) for i in input().split()]
ans=[]
for i in range(a[1]):
  c=[int(i) for i in input().split()]
  if ans==[]:
    ans=range(c[0],c[1]+1)
  else:
    lis=range(c[0],c[1]+1)
    if min(ans)>min(lis) and max(ans)>min(lis):
      ans=range(min(ans),max(ans)+1)
    elif min(ans)>min(lis) and max(ans)<min(lis):
      ans=range(min(ans),max(lis)+1)
    elif min(ans)<min(lis) and max(ans)>min(lis):
      ans=range(min(lis),max(ans)+1)
    elif min(ans)<min(lis) and max(ans)<min(lis):
      ans=range(min(lis),max(lis)+1)
print(len(ans))

Submission status: Wrong Answer

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

min_card = max(l[0] for l in gate_l)
max_card = min(l[1] for l in gate_l)

print(max_card - min_card +1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
l = [] 
r = []
count = 0

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

#idカードの生成
for i in range(0,M):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)
    
for i in range(0,N):
    if max(l) <= i and i <= min(r):
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n,m = LI()
    t = [0 for i in range(n+1)]
    for i in range(m):
        l,r = LI()
        t[l-1] += 1
        t[r] -= 1
    for i in range(n):
        t[i+1] += t[i]
        if t[i]:
            t[i] = 1
    print(sum(t[:n]))
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    q = I()
    m = 0
    l = [-float("inf"),float("inf")]
    x = 0
    num = 0
    for _ in range(q):
        Q = LI()
        if len(Q) == 1:
            print(x,m)
        else:
            z,a,b = Q
            m += b
            if num == 0:
                num += 1
                l = [a,float("inf")]
                x = a
            elif num == 1:
                if a != l[0]:
                    num += 1
                    l = [min(a,l[0]),max(a,l[0])]
                    x = l[0]
                    m += l[1]-l[0]
            else:
                num += 1
                if num % 2:
                    if l[0] <= a < l[1]:
                        m += min(a-l[0],l[1]-a)
                        x = a
                    elif a < l[0]:
                        m += l[0]-a
                        x = l[0]
                        l = [a,l[1]]
                    else:
                        m += a-l[1]
                        x = l[1]
                        l = [l[0],a]
                else:
                    if l[0] <= a < l[1]:
                        if a < x:
                            m += x-a
                            l = [a,x]
                            x = a
                        else:
                            m += a-x
                            l = [x,a]
                    elif a < l[0]:
                        m += x-a
                        x = l[0]
                        l = [l[0],x]
                    else:
                        m += a-x
                        l = [x,l[1]]
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
import sys

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

_min, _max = 1, 100000
for _ in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
print(_max - _min + 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:
import sys

sys.setrecursionlimit(10 ** 5)

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

l, r = map(int, input().split())


def check(i, l, r):
    if i == m:
        return r - l + 1
    l_, r_ = map(int, input().split())
    nl = max(l, l_)
    nr = min(r, r_)
    i += 1
    return check(i, nl, nr)


print(check(1, l, r))

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m=map(int,input().split())
post_b = 0
post_c = n
for i in range(m):
    b,c=map(int,input().split())
    if post_b < b:
        post_b = b
    if post_c > c:
        post_c = c
    print(post_b)
    print(post_c)

if (post_c - post_b + 1)<0:
    print("0")
else:
    print(c-b+1)

Submission status: Wrong Answer

Solution code:
def solve(n, m, list1):
    left = 0
    right = n
    for i in range(len(list1)):
        left = max(list1[i][0], left)
        right = min(list1[i][1], right)
    return max(right-left+1, 0)

n, m = map(int, input().split())
list1 = []
for _ in range(m):
    list1 += [list(map(int, input().split()))]
solve(n, m, list1)

Submission status: Wrong Answer

Solution code:
import numpy as np
from sys import stdin

def main():
    nm = [int(x) for x in stdin.readline().rstrip().split()]
    gate = np.zeros([nm[1], 2], dtype=int)
    
    for i in range(nm[1]):
        g = [int(x) for x in stdin.readline().rstrip().split()]
        gate[i] = g
    
    l_max = np.max(gate[:, 0])
    r_min = np.min(gate[:, 1])+1
    
    print(r_min-l_max)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m=map(int,input().split())
post_b = 0
post_c = n
for i in range(m):
    b,c=map(int,input().split())
    if post_b < b:
        post_b = b
    if post_c > c:
        post_c = c

print(post_c-post_b+1)

Submission status: Wrong Answer

Solution code:
import numpy as np
from sys import stdin

def main():
    nm = [int(x) for x in stdin.readline().rstrip().split()]
    gate = np.zeros([nm[1], 2], dtype=int)
    
    for i in range(nm[1]):
        g = [int(x) for x in stdin.readline().rstrip().split()]
        gate[i] = g
    
    l_max = np.max(gate[:, 0])
    r_min = np.min(gate[:, 1])
    
    print(r_min-l_max)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m=map(int,input().split())
post_b = 0
post_c = n
for i in range(m):
    b,c=map(int,input().split())
    if post_b < b:
        post_b = b
    if post_c > c:
        post_c = c

print(c-b+1)

Submission status: Wrong Answer

Solution code:
import sys

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

_min, _max = 0, 10000001
for _ in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
print(_max - _min + 1)

Submission status: Wrong Answer

Solution code:
import sys

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

_min, _max = 0, 100001
for i in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
print(_max - _min + 1)

Submission status: Wrong Answer

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

import numpy as np

rets = np.array([0] * n)
lmax = n
rmin = 0
for _ in range(m):
  l, r = map(int, input().split())
  lmax = max(l, lmax)
  rmin = min(r, rmin)
print(rmin - lmax + 1 if rmin - lmax + 1 > 0 else 0)

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(L_list)
R = min(R_list)

print(R - L + 1)

Submission status: Wrong Answer

Solution code:
import sys

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


list = []

count = 0
lMin, rMax = -1, -1

for i in range(0,m) :
    l, r = input().split()

    list.append((int(l),int(r)))

#     if list[i][0] <= m and m <= list[i][1] :
#         count = count + m- list[i][0] +1

    if lMin == -1 and rMax == -1:
        lMin, rMax = list[i]
    else:
        if lMin < list[i][0] :
            lMin = list[i][0]
            
        if rMax > list[i][1] :
            rMax = list[i][1]

print(rMax - lMin +1)

Submission status: Wrong Answer

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

count = 0
for c in range(1, N):
    for g in range(M):
        if c >= int(cards[g][0]) and c <= int(cards[g][1]):
            if g == M-1:
                count += 1
        else:
            break

print(count)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
l = []
r = []
for i in range(M):
    x, y = map(int, input().split())
    l.append(x)
    r.append(y)

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

Submission status: Wrong Answer

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

lmax = 1
rmin = N
for _ in range(M):
  l, r = map(int, input().split())
  lmax = max(lmax, l)
  rmin = min(rmin, r)

print(rmin - lmax + 1 if lmax < rmin else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
l = []
r = []
for i in range(M):
    x, y = map(int, input().split())
    l.append(x)
    r.append(y)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
t_list = [[0] * 2 for _ in range(M)]
for i in range(M):
  t_list[i] = list(map(int, input().split()))
bottom = t_list[i][0]
up = t_list[i][1]
for i in range(M):
  t_bottom = t_list[i][0]
  t_up = t_list[i][1]
  if t_bottom > bottom:
    bottom = t_bottom
  if t_up < up:
    up = t_up
print(up - bottom + 1)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import sys

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


cng = []
L_max=0
R_min=float('inf')
for i in range(M):
    L, R = map(int, input().split())
    if(L_max<=L):
        L_max=L
    if(R_min>=R):
        R_min=R
        
if(R_min-L_max==0):
    print(1)
else:
    print(R_min-L_max+1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
n, m = map(int, input().split())
ma = 1
mi = n
for i in range(m):
    l, r  = map(int, input().split())
    ma = max(ma, l)
    mi = min(mi, r)

ans = mi - ma + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
n, m = MI()
lr = [LI() for _ in range(m)]
l = lr[0][0]
r = lr[0][1]
for i in range(1, m):
    if not l <= lr[i][0] <= r and not l <= lr[i][1] <= r:
        print(0)
        exit()
    if l <= lr[i][0] <= r:
        l = lr[i][0] 
    if l <= lr[i][1] <= r:
        r = lr[i][1]
print(r - l + 1)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
              

N, M = map(int, input().split())
#A = input().split()
#A = list(map(int, A))
#print(A)
#A.sort()
#print(A)

cng = []
L_max=0
R_min=1000000000000
for i in range(M):
    L, R = map(int, input().split())
    if(L_max<=L):
        L_max=L
    if(R_min>=R):
        R_min=R
#    print(L_max,R_min)
        
if(R_min-L_max==0):
    print(1)
else:
    print(R_min-L_max+1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
l = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]

sMax = 0
eMin = 0
for s, e in l:
  if sMax < s or sMax == 0:
    sMax = s
  if eMin > e or eMin == 0:
    eMin = e

print(len(range(sMax, eMin))+1)

Submission status: Wrong Answer

Solution code:
card, gate = map(int, input().split())
max_l = 0
min_r = 100000
for i in range(gate):
  l, r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
print(max_l, min_r)    
print(len(range(max_l, min_r+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)

maxl = max(L)
minr = min(R)

ans = minr - maxl + 1
if ans > 0:
    print(ans)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
              

N, M = map(int, input().split())
#A = input().split()
#A = list(map(int, A))
#print(A)
#A.sort()
#print(A)

cng = []
L_max=0
R_min=1000000000000
for i in range(M):
    L, R = map(int, input().split())
    if(L_max<=L):
        L_max=L
    if(R_min>=R):
        R_min=R
        
if(R_min-L_max==0):
    print(1)
else:
    print(R_min-L_max)

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)
max_l=max(L)
min_r=min(R)
if max_l-min_r>=0:
    print(max_l-min_r+1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
isstr=input()
n,m = [int(i) for i in isstr.split(' ')]
mini=-1
maxi=1000000000000000
for i in range(m):
    a,b=[int(i) for i in input().split(' ')]
    if a<=maxi:
        tmp_mini=max(mini,a)
        tmp_maxi=min(maxi,b)
        if(tmp_mini<=tmp_maxi):
            mini=tmp_mini
            maxi=tmp_maxi
        else:
            print(0)
            break
    else:
        mini=maxi=-2
        print(0)
        break
if(mini<maxi):      
    if n>=maxi:
        print(maxi-mini+1)
    elif maxi>n>=mini:
        print(n-mini+1)
    else:
        print(0)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import math

def merge_list(list):
    L = list[-1][0]
    R = sorted(data, key=lambda x: x[1])[-1][1]
    return (L, R)

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

print(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):
  L,R = map(int,input().split(' '))
  left = max(L,left)
  right = min(R,right)
  if right- left < 0:
    print(0)
print(min(right-left+1,N))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
lower = 1
upper = 100000
for i in range(m):
    l, r = map(int, input().split())
    if l >= lower:
        lower = l
    if r <= upper:
        upper = r
if n < upper:
    upper = n
print(upper - lower + 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)

l_max=max(l)
r_min=min(r)

if r < l:
  print(0)
else:
  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):
    tmp = input()
    L.append(tmp[0])
    R.append(tmp[2])

max_L = max(L)
min_R = min(R)
count = 0
for i in (max_L, min_R):
    count += 1
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-1)
	r.append(N-R)

print(N-max(l)-max(r))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
lLst = [0] * M
rLst = [0] * M
ans = 1
for i in range(M):
    lLst[i], rLst[i] = map(int, input().split())

for i in range(M):
    if lLst[M - 1] < rLst[0]:
        ans += rLst[0] - lLst[M - 1]
        break

print(ans)

Submission status: Wrong Answer

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

li = [[0, 99999999999]]

for i in range(M):
    li.append(list(map(int, input().split())))
    if (li[i][0] < li[i+1][0] ):
        L_max = li[i+1][0]
        if (li[i][1] > li[i+1][1]):
            R_min = li[i+1][1]
    elif (li[i ][1] > li[i+1][1]):
            R_min = li[i+1][1]

if (li[M-1][0] < li[M][0] ):
       L_max = li[M][0]
       if (li[M-1][1] > li[M][1]):
          R_min = li[M][1]
elif (li[M-1 ][1] > li[M][1]):
            R_min = li[M][1]

if (L_max > N) or (L_max > R_min):
    print("0")
else:
    print(R_min - L_max + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s = (input().split(' '))

n,m = [int(i) for i in s]

l_list = []
r_list = []

for i in range(m):
    s = (input().split(' '))
    l,r = [int(i) for i in s]
    l_list.append(l)
    r_list.append(r)

range = (max(l_list), min(r_list))

print(min(0, range[1] - range[0] + 1))

Submission status: Wrong Answer

Solution code:
isstr=input()
n,m = [int(i) for i in isstr.split(' ')]
mini=-1
maxi=1000000000000000
for i in range(m):
    a,b=[int(i) for i in input().split(' ')]
    tmp_mini=max(mini,a)
    tmp_maxi=min(maxi,b)
    if(tmp_mini<tmp_maxi):
        mini=tmp_mini
        maxi=tmp_maxi
    elif(tmp_mini==tmp_maxi):
        if tmp_mini<=n:
            print(1)
            break
        else:
            print(0)
            break
    else:
        print(0)
        break
if(mini<maxi):      
    if n>=maxi:
        print(maxi-mini+1)
    elif maxi>n>=mini:
        print(n-mini+1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    id_and_gate = []
    for m in range(0, M):
        tmp = [int(x) for x in input().split()]
        id_and_gate.append(tmp)

    l = 1
    r = 100000
    for j in range(0, M):
        if id_and_gate[j][0] >= l and id_and_gate[j][0] <= r:
            l = id_and_gate[j][0]
        if id_and_gate[j][1] >= l and id_and_gate[j][1] <= r:
            r = id_and_gate[j][1]

    if l == id_and_gate[j][0] and id_and_gate[j][1] == r and M > 1:
        print(0)
    else:
        print(r-l+1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m= map(int,input().split())
l = []
maxn=0
for i in range(m):
    a,b = map(int,input().split())
    if i ==0:
        maxn= b
    if maxn>b:
        maxn = b
    l +=[j for j in range(a,maxn+1)]
l = [i for i in l if l.count(i+1) == m]
print(len(l))

Submission status: Wrong Answer

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

ans_min = lr[0][0]
ans_max = lr[0][1]

for i in range(m - 1):
    t = i + 1
    if lr[t][0] > lr[t - 1][0]:
        ans_min = lr[t][0]
    if lr[t][1] < lr[t - 1][1]:
        ans_max = lr[t][1]

if (ans_max - ans_min + 1) < 0:
    print(0)
else:
    print(ans_max - ans_min + 1)

Submission status: Wrong Answer

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

count = 0
ans=[]
for i in range(M):
    l, r = map(int, input().split())
    if count == 0:
        for j in range(l, r+1):
            ans.append(j)
    else:
        tmp = []
        for j in range(l, r+1):
            tmp.append(j)
        print(ans, tmp)
        ans = list(set(tmp) & set(ans))
    count += 1

print(len(ans))

Submission status: Wrong Answer

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

G=[]
for i in range(N):
    G.append(0)

for i in LR:
    G[i[0]-1]=G[i[0]-1]+1
    G[i[1]-1]=G[i[1]-1]+1

G.count(max(G))

Submission status: Wrong Answer

Solution code:
n, m = map(lambda x: int(x), input().split(' '))
l = []
r = []
for i in range(m):
    l_tmp, r_tmp = map(lambda x: int(x), input().split(' '))
    l.append(l_tmp)
    r.append(r_tmp)

l_max = max(l)
r_min = min(r)

print(r_min - l_max + 1)

Submission status: Wrong Answer

Solution code:
n,m= map(int,input().split())
l = []
maxn=0
for i in range(m):
    a,b = map(int,input().split())
    if i ==0:
        maxn= b
    if maxn>b:
        maxn = b
    l +=[j for j in range(a,maxn+1)]
l = [i for i in range(len(l)+1) if l.count(i+1) == m]
print(len(l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

maxi = float("inf")
mini = 0

for i in range(m):
    l, r = [int(i) for i in input().split()]
    maxi = min(r, maxi)
    mini = max(l, mini)

print(maxi-mini+1)

Submission status: Wrong Answer

Solution code:
N, M= map(int, input().split()) 
L = [0]*M 
R = [0]*M
if M == 1:
  print(N)
else:
  L[0], R[0] = map(int, input().split())
  for i in range(1,M):
    L[i], R[i] = map(int, input().split())
    s = set(range(L[0],R[0]+1))
    ans = s & (set(range(L[i],R[i]+1)))
  print(len(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
import sys
s = sys.stdin.readlines()
N, M = map(int, s[0].split())
out_list = []
for i in range(1, N + 1):
    out_list.append(i)
for e in s[1:]:
    L, R = map(int, e.split())
    for idx, num in enumerate(out_list):
        if num < L or num > R:
            out_list.pop(idx)
print(len(out_list))

Submission status: Wrong Answer

Solution code:
import numpy as np
a=[int(i) for i in input().split()]
ans=[]
for i in range(a[1]):
  c=[int(i) for i in input().split()]
  if ans==[]:
    ans=range(c[0],c[1]+1)
  else:
    lis=range(c[0],c[1]+1)
    if min(ans)>min(lis) and max(ans)>min(lis):
      ans=range(min(ans),max(ans)+1)
    elif min(ans)>min(lis) and max(ans)<min(lis):
      ans=range(min(ans),max(lis)+1)
    elif min(ans)<min(lis) and max(ans)>min(lis):
      ans=range(min(lis),max(ans)+1)
    elif min(ans)<min(lis) and max(ans)<min(lis):
      ans=range(min(lis),max(lis)+1)

Submission status: Wrong Answer

Solution code:
import numpy as np
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)
L, R = np.array(L), np.array(R)
np.append(L, R)
print(np.sum((L[M-1]<=L)*(L<R[0])))

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N,M = [int(x) for x in input().split()]
Llist =[]
Rlist =[]
for i in range (M):
    L,R = [int(x) for x in input().split()]
    Llist.append(L)
    Rlist.append(R)
 
lmax = max(Llist)
Rmax = min(Rlist)

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

Submission status: Wrong Answer

Solution code:
x = input()
li = x.split()
n = int(li[0])
m = int(li[1])
o = 0
y = input()
e = y.split()
u = int(e[0])
t = int(e[1])
q = u
w = t
for k in range (m - 1):
  y = input()
  e = y.split()
  l = int(e[0])
  r = int(e[1])
  if (q < l and w < r):
    q = l
    w = r
if(q < t):
  if(n < q):
    o =0
  elif(n <= t):
    o = n - q + 1
  else:
    o = t -q + 1
else:
  o = 0
    
  

print(o)

Submission status: Wrong Answer

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

id = []
for i in range(M):
    id += [L[i:] + R[:i + 1]]
print(id)
com = set(id[0])
for j in range(1, M):
    com = com & set(id[j])
com_max = max(com)
com_min = min(com)
print(com_max - com_min + 1)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
N,M= (int(i) for i in input().split(" "))  

LR= np.array([[int(i) for i in input().split()] for i in range(M)]) 

L=LR[-1,0]
R=LR[0,1]


el=np.sum(np.logical_and(LR<L,R<LR))


print(int(abs(R-L)+1-el))

Submission status: Wrong Answer

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

maxi_L = 0
mini_R = 10000000
A,B = (int(x) for x in input().split())
L_R.append([A,B])
L_R.append([A,B])
if A > maxi_L:
    maxi_L = A
if B < mini_R:
    mini_R = B
for i in range(2,M+1):
    A,B = (int(x) for x in input().split())
    L_R.append([A,B])
    if A > maxi_L:
        maxi_L = A
    if B < mini_R:
        mini_R = B
#mini = 1000000
#for i in range(len(L_R)):
#    if L_R[i][0] < mini:
#        mini = L_R[i][0]
#maxi = 0
#for i in range(len(L_R)):
#    if L_R[i][1] > maxi:
#        maxi = L_R[i][1]

#num = 0
#maxi = max(maxi,N)
#for x in range(mini,maxi+1):
#    n = 0
#    for i in range(1,M+1):
#        if L_R[i][0] <= x <= L_R[i][1]:
#            n += 1
#    if n == M:
#        num += 1
#    else:
#        pass


n = mini_R  - maxi_L + 1
if mini_R > N and maxi_L <N:
    n = 0
print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split(" "))
L = 1
R = N
for m in range(M):
    L_in, R_in = map(int, input().split(" "))
    if L_in > L:
        L = L_in
    if R_in < R:
        R = R_in
print(R - L + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# abc127/abc127_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))


def main():
    N, M = i2nn()
    L, R = (0, N)
    for i in range(M):
        Li, Ri = i2nn()
        if L < Li:
            L = Li
        if Ri < R:
            R = Ri
    print(R - L + 1)
    return

main()