Problem:


Score : 300 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq L_i \leq R_i \leq N

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M

Output

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

Sample Input 1

4 2
1 3
2 4

Sample Output 1

2

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

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

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

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

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

Sample Input 2

10 3
3 6
5 7
6 9

Sample Output 2

1

Sample Input 3

100000 1
1 100000

Sample Output 3

100000



Sample input:
4 2
1 3
2 4


Sample output:
2

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
info=[]
for i in range(m):
    info.append(list(map(int,input().split())))
start,goal=info[0][0],info[0][1]

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
info=[]
for i in range(m):
    info.append(list(map(int,input().split())))
start,goal=info[0][0],info[0][1]

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

Submission status: Wrong Answer

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

for _ in range(M):
    L, R = map(int, input().split())
    L_set.add(L)
    R_set.add(R)

print(max(L_set) - min(R_set) + 1)

Submission status: Wrong Answer

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

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

res = min_R - max_L + 1
print(res)

Submission status: Wrong Answer

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

L, R = [], []
for i in range(M):
    l, r = list(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())
(start, end) = (0, 100000)
for _ in range(M):
    s, e = map(int, input().split())
    start = max((start, s))
    end = min((end, e))
print(end - start + 1)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    seq = np.zeros(N, dtype=int)
    for _ in range(M):
        l, r = map(int, input().split())
        seq[l-1] = 1
        if r < N:
            seq[r] = -1
    csum = np.cumsum(seq)
    ans = np.add.reduce(np.where(csum == M, 1, 0))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# master ID cardの数を求める問題
# 単純に考えてNまいのIDcardに対して、それが全てを通過できるか考えると、
# 計算量はO(N*M)かかるので10^5*10^5で10^10となり、通らない
# 番目の ID カードのうちどれか 1 枚を持っていれば通過できます。
# とのことから、i 番目のゲートを通るIDカードは連続で並んでいるので、
# Mのゲートに対して、開始点(Li)と終了点(Ri)のmax,minをとれば良い
n,m = map(int,input().split())
max_l = 0
min_r = n
for i in range(m):
  l,r = map(int,input().split())
  if max_l <  l:
    max_l = l
  if min_r > r:
    min_r = r
print(min_r - max_l +1)

Submission status: Wrong Answer

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

import numpy as np  # 1.8.2

def main():
    N, M = i2nn()
    LR = np.array(ii2nnn(M))
    L = LR[:,0]
    R = LR[:,1]
    n = np.min(R) - np.max(L) + 1
    n = np.max(n, 0)
    print(n)

main()

Submission status: Wrong Answer

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

import numpy as np  # 1.8.2

def main():
    N, M = i2nn()
    LR = np.array(ii2nnn(M))
    L = LR[:,0]
    R = LR[:,1]
    n = np.min(R) - np.max(L) + 1
    print(n)

main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L = []
R = []
for i in range(M):
    tmp = list(map(int, input().split()))
#    print(tmp)
    L.append(tmp[0])
    R.append(tmp[1])


kukan = [max(L), min(R)]
sa = kukan[1] - kukan[0]
if sa > 0:
    print(sa + 1)
else:
    print("0")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L = []
R = []
for i in range(M):
    tmp = list(map(int, input().split()))
#    print(tmp)
    L.append(tmp[0])
    R.append(tmp[1])

kukan = [max(L), min(R)]

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(num_card, num_gate, inputs):
    gate_card = list(map(lambda x: string_to_int(x), inputs))
    min_card = 1
    max_card = num_card
    for d in gate_card:
        if d[0] > min_card:
            min_card = d[0]
        if d[1] < max_card:
            max_card = d[1]
    return max_card - min_card + 1


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N, M] = string_to_int(input())
    ret = solve(N, M, inputs(M))
    print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
li=[]
for i in range(m):
    a=list(map(int,input().split()))
    li.append(a)
l=0
r=1000000
for i in range(m):
    if li[i][0]>l:
        l=li[i][0]
    if li[i][1]<r:
        r=li[i][1]
b=[i for i in range(l,r+1)]
c=[]

for i in range(m):
    if li[i][0] in b:
        c.append(li[i][0])
        
    if li[i][1] in b:
        c.append(li[i][1])
c=set(c)
print(len(c))

Submission status: Wrong Answer

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

min = 0
max = 100000

for x in range(m):
    tmp_min, tmp_max = [int(y) for y in input().split()]
    if min < tmp_min:
        min = tmp_min
    if max > tmp_max:
        max = tmp_max                      
if max - min > 0:
    print(max - min + 1)
else:
    print(0)

Submission status: Wrong Answer

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

min = 0
max = 100000

for x in range(m):
  tmp_min, tmp_max = [int(y) for y in input().split()]
  if min < tmp_min:
    min = tmp_min
  if max > tmp_max:
    max = tmp_max
    
print(max - min + 1)

Submission status: Wrong Answer

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

min = 0
max = 100000

for x in range(m):
  tmp_min, tmp_max = [int(y) for y in input().split()]
  if min <= tmp_min:
    min = tmp_min
  if max >= tmp_max:
    max = tmp_max
    
print(max - min + 1)

Submission status: Wrong Answer

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

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

# print(left,right)
print(right-left+1)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 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 _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)


N, M = LI()
LR = []

for i in range(M):
    LR.append(LI())

left, right = 0, inf
for lr in LR:
    left = max(left, lr[0])
    right = min(right, lr[1])
#  print(left, right)
print(right - left + 1)

Submission status: Wrong Answer

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

lmax = 0
rmin = N

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

print(rmin-lmax+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L = []
R = []
LR = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    L.append(LR[i][0])
countL = 0
countL = max(L)
for j in range(M):
    R.append(LR[j][1])
countR = 0
countR = min(R)
if countR >= countL:
    print(0)
else:
    print(countR-countL+1)

Submission status: Wrong Answer

Solution code:
N,M=(int(x) for x in input().split())
L=0
R=N
for i in range(M):
  Li,Ri=(int(x) for x in input().split())
  L=Li if Li>L else L
  R=Ri if Ri<R else R
  print(str(L)+str(R))
ans=R-L+1 if R>=L else 0
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=(int(x) for x in input().split())
L=0
R=N
for i in range(M):
  Li,Ri=(int(x) for x in input().split())
  L=Li if Li>L else L
  R=Ri if Ri<R else R
print(R-L+1)

Submission status: Wrong Answer

Solution code:
N,M=(int(x) for x in input().split())
L=0
R=N
for i in range(M):
  Li,Ri=(int(x) for x in input().split())
  L=Li if Li>L else L
  R=Ri if Ri<R else R
print(Ri-Li+1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L = []
R = []
LR = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    L.append(LR[i][0])
countL = 0
countL = max(L)
for j in range(M):
    R.append(LR[j][1])
countR = 0
countR = min(R)
print(countR-countL+1)

Submission status: Wrong Answer

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

if len(lst) == 1:
    print(n)
    exit()

l_lst = []

for l in lst:
    ral = list(range(l[0], l[-1]+1))
    l_lst.append(ral)



c = {}
arr = []
for i in range(1, len(l_lst)):
    if i == 1:
        ss = set(l_lst[i-1]) & set(l_lst[i])
        c = ss
    else:
        c = set(l_lst[i]) & c


print(len(list(c)))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
x=[]
listA=[]
for i in range(0,M):
  x=list(map(int,input().split()))
  listA.append(x)
listB=[]
listC=[]
for i in range(0,M):
  listB.append(listA[i][0])
  listC.append(listA[i][1])
print(abs(max(listB)-min(listC))+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
maxl=1
minr=n
while m:
  l,r=map(int,input().split())
  maxl=max(maxl,l)
  minr=min(minr,r)
  m-=1
print(max(0,maxl-minr+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())
a=L[0]
for i in range(M):
  if a<L[i]:
    a=L[i]
b=R[0]
for i in range(M):
  if b>R[i]:
    b=R[i]
if b-a+1>1: 
  print(b-a+1)
else:
  print("0")

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())
a=L[0]
for i in range(M):
  if a<L[i]:
    a=L[i]
b=R[0]
for i in range(M):
  if b>R[i]:
    b=R[i]
print(b-a+1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
card = []
for _ in range(M):
    L, R = map(int, input().split())
    left = min(L, R)
    right = max(L, R)
    card.append([left, right])
pass_card = {int(i) for i in range(card[0][0], card[0][1]+1)}
for i in range(1,M):
    if len(pass_card) == 0:
        exit()
    else:
        pass_id = {int(i) for i in range(card[i][0], card[i][1]+1)}
        pass_card = pass_card & pass_id
print(len(pass_card))

Submission status: Wrong Answer

Solution code:
def prison(left, right):
    if left <= right:
        print(right-left+1)
    else:
        print(0)

N, M = map(int, input().split())
left_limit=0
right_limit=N
 
for i in range(M):
    LEFT, RIGHT = map(int, input().split())
    if LEFT > left_limit:
        left_limit = LEFT
    if i == 0:
        right_limit = RIGHT
        
prison(left_limit, right_limit)

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin
import numpy as np

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

L = np.array(L)
R = np.array(R)
  
print(R.min() - L.max() + 1)

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin
import numpy as np

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

inputs = np.vstack((L, R)).T
  
count = 0
for i in range(1, N+1):
  out = (inputs[:, 0] >= i) & (inputs[:, 1] <= i)
  if out.all():
    count += 1
  
print(count)

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin
import numpy as np

N, M = map(int, input().split())
L, R = list(), list()
for i in range(M):
  l,r = stdin.readline().rstrip().split()
  L.append(int(l))
  R.append(int(r))

inputs = np.vstack((L, R)).T
  
count = 0
for i in range(1, N+1):
  out = (inputs[:, 0] >= i) & (inputs[:, 1] <= i)
  if out.all():
    count += 0
  
print(count)

Submission status: Wrong Answer

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

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
#C
N, M = map(int, input().split())
Table = [list(map(int, input().split())) for _ in range(M)]
Table.sort(key=lambda x:x[0])
Table.sort(key=lambda x:x[1])
#print(f'Table:{Table}')
first = Table[0][0]
end = Table[0][1]
Table.pop(0)
ans = 1
#print(f'first:{first} end:{end}')
for task in Table:
    #print(f'task:{task}')
    num = task[0]
    #print(f'num:{num}')
    if num <= end:
        first = num
    else:
        ans = 0
        break

if ans == 0:
    print(ans)
else:
    print(end-first+1)

Submission status: Wrong Answer

Solution code:
#C
N, M = map(int, input().split())
Table = [list(map(int, input().split())) for _ in range(M)]
Table.sort(key=lambda x:x[0])
Table.sort(key=lambda x:x[1])
first = Table[0][0]
end = Table[0][1]
Table.pop(0)
for task in Table:
    num = task[0]
    if num <= end:
        first = num
    else:
        print('0')
        exit()
print(end-first+1)

Submission status: Wrong Answer

Solution code:
#C
N, M = map(int, input().split())
Table = [list(map(int, input().split())) for _ in range(M)]
Table.sort(key=lambda x:x[1])
first = Table[0][0]
end = Table[0][1]
Table.pop(0)
for task in Table:
    num = task[0]
    if num <= end:
        first = num
    else:
        print('0')
        exit()
print(end-first+1)

Submission status: Wrong Answer

Solution code:
#C
N, M = map(int, input().split())
Table = [list(map(int, input().split())) for _ in range(M)]
Table.sort(key=lambda x:x[1])
#print(f'Table:{Table}')
first = Table[0][0]
end = Table[0][1]
#print(f'first:{first} end:{end}')
for i, task in enumerate(Table):
    #print('----------------------------------------------------')
    if i == 0:
        continue
    #print(f'task:{task}')
    num = task[0]
    #print(f'num:{num}')
    if num <= end:
        first = num
    else:
        print('0')
        exit()
print(end-first+1)

Submission status: Wrong Answer

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

min_value = 1
max_value = n

for _ in range(m):
  l, r = map(int, input().split())
  if l >= min_value:
    min_value = l
  if r <= max_value:
    max_value = r

Answer = max_value - min_value +1

print(Answer)

Submission status: Wrong Answer

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

min_value = 1
max_value = n

for _ in range(m):
  l, r = map(int, input().split())
  if l > min_value:
    min_value = l
  if r < max_value:
    max_value = r

Answer = max_value - min_value +1

print(Answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = [int(i) for i in input().split()]
arr_list = [input().split() for i in range(M)]
num_list = [list(range(int(arr[0]),int(arr[1])+1)) for arr in arr_list]
num_list.insert(0, list(range(1,N+1)))

for i in range(M):
  num_list[i+1] = set(num_list[i])&set(num_list[i+1])

print(num_list[-1])

Submission status: Wrong Answer

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

LN, RN = 1,N
for i in range(M):
  L,R = list(map(int, input().split()))
  LN = max(LN,L)
  RN = min(RN,R)
  
print(RN-LN+1)

Submission status: Wrong Answer

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

left = []
right= []

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

l = max(left)
right.sort()
for i in right:
    if l <= i :
        r = i
        break

print(r-l+1)

Submission status: Wrong Answer

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

left = []
right= []

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

l = max(left)
right.sort()
for i in range(M):
    if l <= right[i] :
        r = right[i]
        break

print(r-l+1)

Submission status: Wrong Answer

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

left = []
right= []

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

l = max(left)
r = min(right)

print(r-l+1)

Submission status: Wrong Answer

Solution code:
data = list(map(lambda x: int(x),input().split(" ")))

cardNum = []

for n in range(data[1]):
	cardNum.append(list(map(lambda x: int(x),input().split(" "))))


card = [0]*(data[0])

check = [0,1000000]

for n in range(data[1]):
	if check[0] < cardNum[n][0]:
		check[0] = cardNum[n][0]
	if check[1] > cardNum[n][1]:
		check[1] = cardNum[n][1]

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

Submission status: Wrong Answer

Solution code:
data = list(map(lambda x: int(x),input().split(" ")))

cardNum = []

for n in range(data[1]):
	cardNum.append(list(map(lambda x: int(x),input().split(" "))))


card = [0]*(data[0])

check = [1,100000]

for n in range(data[1]):
	if check[0] < cardNum[n][0]:
		check[0] = cardNum[n][0]
	if check[1] > cardNum[n][1]:
		check[1] = cardNum[n][1]

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

Submission status: Wrong Answer

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

ll = 0
rr = 10 ** 5
dd = 0
lr = []
for i in range(M):
    l, r = map(int, input().split())
    ll = max(ll, l)
    rr = min(rr, r)
    lr.append((l, r))
lr.sort(key=lambda x: (x[0], x[1]))

for i in range(M):
    if i > 0:
        if lr[i] == lr[i-1]:
            dd += 1

if rr < ll:
    print(0)
else:
    print(rr-ll+1+dd)

Submission status: Wrong Answer

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

ll = 0
rr = 10 ** 5
dd = 0
lr = []
for i in range(M):
    l, r = map(int, input().split())
    ll = max(ll, l)
    rr = min(rr, r)
    lr.append((l, r))
lr.sort(key=lambda x: (x[0], x[1]))

for i in range(M):
    if i > 0:
        if lr[i] == lr[i-1]:
            dd += 1
print(rr-ll+1+dd)

Submission status: Wrong Answer

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

ll = 0
rr = 10 ** 5

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
ids = [list(map(int, input().split())) for _ in range(m)]
l = []
r = []
for id in ids:
        l.append(id[0])
        r.append(id[1])
if max(r) <= min(r):
        print(min(r) - max(l) + 1)
else:
        print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
ids = [list(map(int, input().split())) for _ in range(m)]
l = []
r = []
for id in ids:
        l.append(id[0])
        r.append(id[1])
if min(r) < max(r):
        print(0)
else:
        print(min(r) - max(l) + 1)

Submission status: Wrong Answer

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

L = 1
R = N
for d in D:
    if L<=d[0]<=R or L<=d[1]<=R:
        L = max(L, d[0])
        R = min(R, d[1])
    else:
        print(0)
        break
else:
    print(R-L+1)

Submission status: Wrong Answer

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

L = 1
R = N
for d in D:
    if L<=d[0]<=R or L<=d[1]<=R:
        L = max(L, d[0])
        R = min(R, d[1])
    else:
        print(0)
        break
    print("[{}, {}]".format(L, R))
else:
    print(R-L+1)

Submission status: Wrong Answer

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

L = 1
R = N
for d in D:
    if not(L<=d[0]) and not(R<=d[1]):
        print(0)
        break
    if L<=d[0]:
        L = d[0]
    if d[1]<=R:
        R = d[1]
else:
    print(R-L+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 L<=a<=R:
        L=a
    elif L<=b<=R:
        R=b
    else:
        print(0)
        exit(0)
print(R-L+1)

Submission status: Wrong Answer

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

for i in range(M):
        l.append(A[i][0])
for i in range(M):
        r.append(A[i][1])

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

Submission status: Wrong Answer

Solution code:
import numpy as np

a = input().split(" ")
N = int(a[0])
M = int(a[1])
gate = []
for i in range(M):
    a = input().split(" ")
    gate.append([int(a[0]),int(a[1])])

gate = np.array(gate)

max = gate.max(axis=0)[0]
min = gate.min(axis=0)[1]

if max > min:
    print(0)
elif max == min:
    if max < N:
        print(1)
    else:
        print(0)
else:
    if N < max:
        print(0)
    elif max <= N and N <= min:
        print(N-max+1)
    else:
        print(min-max+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


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

    A = []
    B = []

    for _ in range(m):
        a, b = list(map(int, input().split()))
        A.append(a)
        B.append(b)

         
    l = max(A)
    r = min(B)
    #print(l, r)

    if r >= l:
        return r - l + 1
    else:
        return l - r + 1

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



"""
for i in range(1, n + 1):
        for j in range(m):
            if gate[j][0] <= i and i <= gate[j][1]:
                if j == len(gate) - 1:
                    result += 1
                continue
            else:
                break
"""

Submission status: Wrong Answer

Solution code:


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

    A = []
    B = []

    for _ in range(m):
        a, b = list(map(int, input().split()))
        A.append(a)
        B.append(b)

         
    l = max(A)
    r = min(B)
    #print(l, r)

    return r - l + 1

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



"""
for i in range(1, n + 1):
        for j in range(m):
            if gate[j][0] <= i and i <= gate[j][1]:
                if j == len(gate) - 1:
                    result += 1
                continue
            else:
                break
"""

Submission status: Wrong Answer

Solution code:


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

    gate = []

    for _ in range(m):
        ngate = list(map(int, input().split()))
        gate.append(ngate)
    print(gate)

    result = 0
    for i in range(1, n + 1):
        for j in range(m):
            if gate[j][0] <= i and i <= gate[j][1]:
                if j == len(gate) - 1:
                    result += 1
                continue
            else:
                break

    
    return result


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

Submission status: Wrong Answer

Solution code:
n,m = input().split()
LR =  [list(map(int,input().split())) for i in range(int(m))]
s = max([i[0] for i in LR])
e = min([i[1] for i in LR])
print(e-s+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)
print(min(rl)-max(ll)+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().rstrip().split())
count = 0
L_max = -10**10
R_min = 10**10
for i in range(M):
    L,R = map(int, input().split())
    if L_max < L:
        L_max = L
    if R < R_min:
        R_min = R
print(R_min-L_max+1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

sidel = 1
sider = n
for lr in range_lr:
    sidel = max(sidel, lr[0])
    sider = min(sider, lr[1])
print(sider-sidel+1)

Submission status: Wrong Answer

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

left = 0
right = n

for i in li:
  left = max(i[0], left)
  right = min(i[1], right)
  
if right <= left:
  print(0)
else:
  print(right - left + 1)

Submission status: Wrong Answer

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

left = 0
right = n

for i in li:
  left = max(i[0], left)
  right = min(i[1], right)
  
print(right - left + 1)

Submission status: Wrong Answer

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

l = []
r = []

for i in range(m):
	d = [int(i) for i in input().split()]
	l.append(d[0])
	r.append(d[1])
	
print(min(r) - max(l) + 1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
LR = []
for _ in range(M):
    LR.append(list(map(int, input().split())))
mn, mx = 0, int(1e5)
for i, j in LR:
    if i > mn:
        mn = i
    if j < mx:
        mx = j
        
print(mx - mn + 1)

Submission status: Wrong Answer

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

l_max = 0
r_min = N
for m in range(M):
    left, right = map(int, input().split())
    l_max = max(l_max, left)
    r_min = min(r_min, right)

print(r_min-l_max + 1)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,m=LI()

  l=[]
  for _ in ' '*m:
    a,b=LI()
    l.append([a,1])
    l.append([b,-1])

  l=sorted(l,key=lambda x:x[1],reverse=True)
  l=sorted(l,key=lambda x:x[0])

  sm=st=0
  for x in l:
    sm+=x[1]
    if sm==m:
      st=x[0]
    if sm!=m and st!=0:
      return x[0]-st+1

print(main())

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
i_max = n -1
i_min = 0
for x in range(m):
    l, r = map(int, input().split())
    i_max = min(r, i_max)
    i_min = max(l, i_min)

print(max(0,i_max - i_min + 1))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l, r = [],[]
i_max = n -1
i_min = 0
for x in range(m):
    l, r = map(int, input().split())
    i_max = min(r, i_max)
    i_min = max(l, i_min)
    if (i_max - i_min) < 0:
        print(0)
        exit()

print(i_max - i_min + 1)