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 = list(map(int, input().split()))
mn = 0
mx = N
f = False
for i in range(M):
    tmn, tmx = list(map(int, input().split()))
    if mn < tmn < mx:
        mn = tmn
    else:
        f = True
        break
    if mn < tmx < mx:
        mx = tmx
    else:
        f = True
        break
if f:
    print(0)
else:
    print(mx - mn + 1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
S = [None]*m
L = 0
R = n

for i in range(m):
    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:
N, M = list(map(int, input().split()))
mn = 0
mx = N
for i in range(M):
    tmn, tmx = list(map(int, input().split()))
    if mn < tmn:
        mn = tmn
    if tmx < mx:
        mx = tmx
print(mx - mn + 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())
LL = max(L)
RR = min(R)
if LL <= M <= RR:
    print(RR - LL + 1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l_max = 1
r_min = 10 ** 5

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

print(r_min - l_max + 1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L = [0] * M
R = [0] * M
ID = [0] * M
N = {i for i in range(N)}
for i in range(M):
    L[i], R[i] = map(int, input().split())
    N = N.intersection({i for i in range(L[i], R[i] + 1)})

print(len(N))

Submission status: Wrong Answer

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

l_tmp = 0
r_tmp = n+1
for i in range(m):
  l, r = map(int, input().split())
  l_tmp = l if l > l_tmp else l_tmp
  r_tmp = r if r < r_tmp else r_tmp
    
print(r_tmp-l_tmp+1)

Submission status: Wrong Answer

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

mi = -1
ma = 10**5 + 1
for i in range(M):
    l = lr[i][0]
    r = lr[i][1]
    if mi <= l:
        mi = l
    if r <= ma:
        ma = r

print(ma - mi + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Mini = 0
Max = N

for i in range(M):
    if Mini <= S[i][0]:
        Mini = S[i][0]
    if Max >= S[i][1]:
        Max = S[i][1]
print(Max-Mini+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a_min = 1
a_max = n
for _ in range(m):
  l,r = map(int,input().split())
  a_min = max(a_min,l)
  a_max = min(a_max,r)
print(a_max-a_min+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)
  
if max(R_list) >= max(L_list):
  print(max(R_list)  - max(L_list) + 1)
else:
  print(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)
  
if max(R_list) >= max(L_list):
  print(max(R_list)  - max(L_list))
else:
  print(0)

Submission status: Wrong Answer

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

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

unq = set(list)

counter = 0

for i in unq:
  if list.count(i) == M:
    counter +=1
    
print(counter)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
maxn,minn = map(int,input().split())
for i in range(M-1):
    L,R = map(int,input().split())
    if L > maxn:
        maxn = L
    if R < minn:
        minn = R
if N < maxn:
    ans = minn-N+1
else:
    ans = minn - maxn + 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
maxn,minn = map(int,input().split())
for i in range(M-1):
    L,R = map(int,input().split())
    if L > maxn:
        maxn = L
    if R < minn:
        minn = R
ans = minn - maxn + 1
print(ans)

Submission status: Wrong Answer

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

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

l,r = 1,N
for i in range(M):
    l1,r1 = map(int, input().split())
    if l1>l:
        l = l1
    if r1<r:
        r = r1

print(r-l+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)
L.sort(reverse=True)
R.sort()
ans =0
for i in range(n):
    if i >=L[0] and i <=R[0]:
        ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from operator import add, mul
n,m=map(int,input().split())
a=[0]*(n+1)
b=[list(map(int,input().split())) for _ in range(m)]
for  i in range(m):
    a[b[i][0]-1]+=1
    a[b[i][1]]-=1
c=list(accumulate(a,add))
d=max(c)
if c.count(d)==m:
    print(c.count(d))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from operator import add, mul
n,m=map(int,input().split())
a=[0]*(n+1)
b=[list(map(int,input().split())) for _ in range(m)]
for  i in range(m):
    a[b[i][0]-1]+=1
    a[b[i][1]]-=1
c=list(accumulate(a,add))
d=max(c)
if c.count(d)>1:
    print(c.count(d))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from operator import add, mul
n,m=map(int,input().split())
a=[0]*(n+1)
b=[list(map(int,input().split())) for _ in range(m)]
for  i in range(m):
    a[b[i][0]-1]+=1
    a[b[i][1]]-=1
c=list(accumulate(a,add))
d=max(c)
print(c.count(d))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
L,R=0,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:
#!/usr/bin/env python

def main():
    N, M = map(int, input().split())
    INF = float('inf')

    LR = [-INF, INF]
    for _ in range(M):
        L, R = map(int, input().split())
        if LR[0] < L:
            LR[0] = L
        if LR[1] > R:
            LR[1] = R
    if LR[1] > LR[0]:
        return int(LR[1] - LR[0] + 1)
    else:
        return 0

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

def main():
    N, M = map(int, input().split())
    INF = float('inf')

    LR = [-INF, INF]
    for _ in range(M):
        L, R = map(int, input().split())
        if LR[0] < L:
            LR[0] = L
        if LR[1] > R:
            LR[1] = R
    return int(LR[1] - LR[0] + 1)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

max = 0
min = 10000000000
hantei = 0

for i in range(M):
    if max < list[i][0] :
        max = list[i][0]
    if min >= list[i][1] :
        min = list[i][1]       
    if max < list[i][0] and i != 0:
        #print(max,list[i][0])
        hantei = 1
        break
    if min > list[i][1] and i != 0:
        hantei = 1
        break

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

Submission status: Wrong Answer

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

max = 0
min = 10000000000

for i in range(M):
    if max < list[i][0] :
        max = list[i][0]


for i in range(M):
    if min > list[i][1] :
        min = list[i][1]
   
if min >= max:
    print(min - max + 1)
else:
    print(1)

Submission status: Wrong Answer

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

max = 0
min = 10000000000
count = 0

for i in range(M):
    if max < list[i][0] :
        count = 0
        max = list[i][0]
    elif max == list[i][0] :
        count += 1

for i in range(M):
    if min > list[i][1] :
        min = list[i][1]
   

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

Submission status: Wrong Answer

Solution code:
c,g=map(int,input().split())

st=[]
en=[]

for i in range(g):
	s,e=map(int,input().split())
	st.append(s) 
	en.append(e)

res=min(en)-max(st)+1
print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

P0 = []
tmp = []
common = []

if M == 1:
	print(N)
	exit()

#print(LR)
for i in range(LR[0][0], LR[0][1] + 1):
	P0.append(i)

#print(P0)

for j in range(1, M):
	for k in range(LR[j][0], LR[j][1] + 1):
		#print(k)

		tmp.append(k)
		
	else:
		common = set(P0) & set(tmp)
		tmp = []

print(len(common))

Submission status: Wrong Answer

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

l, r = 1, n
for i 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 = [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())
  
ans = min(R)-(max(L)-1)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
s=[0]*n
max_=1
min_=n
for _ in range(m):
    b,c=map(int,input().split())
    if b>max_:
        max_=b
    if c<min_:
        min_=c
print(min_-max_+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve():
    n, m = map(int, input().split())
    lrs = list(list(map(int, input().split())) for _ in range(m))
    max_l, min_r = max([l for l, r in lrs]), min([r for l, r in lrs])
    return min_r - max_l + 1


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

Submission status: Wrong Answer

Solution code:
# ABC 127 c
n, m = [int(el) for el in input().split(' ')]
max_l = 0
min_r = n
for i in range(m):
    l, r = [int(el) for el in input().split(' ')]
    max_l = max(max_l, l)
    min_r = min(min_r, r)

print(min_r - max_l + 1)

Submission status: Wrong Answer

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

for _ in range(m):
  s = []
  for v in input().split():
    s.append(int(v))
  l.append(s)

current_common = set(range(l[0][0], l[0][1]+1))
for i in range(len(l)-1):
  common = current_common & set(range(l[i+1][0], l[i+1][1]))
  if len(common) > 0:
    current_common = common
  else:
    print(0)
    
ans = set()
for j in current_common:
  if j < n:
    ans.add(j)
    
print(list(ans))

Submission status: Wrong Answer

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

for _ in range(m):
  s = []
  for v in input().split():
    s.append(int(v))
  l.append(s)

current_common = set(range(l[0][0], l[0][1]+1))
for i in range(len(l)-1):
  common = current_common & set(range(l[i+1][0], l[i+1][1]))
  if len(common) > 0:
    current_common = common
  else:
    print(0)
    
print(list(current_common))

Submission status: Wrong Answer

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

l = []


def match(a, b):
    l = []
    for i in a:
        if i in b:
            l.append(i)
    return l


def make_list(l):
    a = []
    for i in range(l[0], l[1]+1):
        a.append(i)
    return a


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

if m == 1:
    print(l[0][1])
    exit()

a = make_list(l[0])
b = make_list(l[1])
x = match(a, b)

for i in range(2, m):
    x = match(x, l[i])

print(len(x))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
lm=[0]*m
rm=[0]*m

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

print(min(rm)-max(lm)+1)

Submission status: Wrong Answer

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

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

print(min(rm)-max(lm)+1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

lst = [list(map(int, input().split())) for _ in range(M)]

lower = 1
upper = N
for l, u in lst:
    if l > lower:
        lower = l

    if u < upper:
        upper = u

    if upper <= lower:
        print(0)
        exit()

print(upper - lower + 1)

Submission status: Wrong Answer

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

lst = [list(map(int, input().split())) for _ in range(M)]

lower = 1
upper = N
for l, u in lst:
    if l > lower:
        lower = l

    if u < upper:
        upper = u


print(upper - lower + 1)

Submission status: Wrong Answer

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

for _ in range(m):
  s = []
  for v in input().split():
    s.append(int(v))
  l.append(s)

current_common = set(range(l[0][0], l[0][1]+1))
for i in range(len(l)-1):
  common = current_common & set(range(l[i+1][0], l[i+1][1]))
  if len(common) > 0:
    current_common = common
  else:
    print(0)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L = 0
R = 10**5 +2
for i in range(M):
    l,r = map(int, input().split())
    if L < l:
        L = l
    if R > r:
        R = r
        
ans = 0
for i in range(N):
    if L <= i <= R:
        ans += 1
        
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(R-L+1)

Submission status: Wrong Answer

Solution code:
def resolve():
    N,M = map(int,input().split())
    LL,RR = [],[]
    for i in range(M):
        L,R = map(int,input().split())
        LL.append(L)
        RR.append(R)

    bool_id = [1]*N
    lmin = -1
    rmax = 10**6
    for i in range(M):
        lmin = max(lmin,LL[i])
        rmax = min(rmax,RR[i])
    print(rmax-lmin+1)

resolve()

Submission status: Wrong Answer

Solution code:
#127
import sys
n, m = list(map(int, input().split(' ')))
gate_info = []
#0 : L, 1 : R
for i in range(m):
    gate_info.append(list(map(int, input().split(' '))))
result = [1,n]
for i in range(m):
    if result[0] < gate_info[i][0]:
        result[0] = gate_info[i][0]
    if result[1] > gate_info[i][1]:
        result[1] = gate_info[i][1]
    if result[1] - result[0] <= 0:
        print(0)
        sys.exit()
print(int(result[1]-result[0]+1))

Submission status: Wrong Answer

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

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

print(min(rr)-max(ll)+1)

Submission status: Wrong Answer

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

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

for i in li:
	print(i)

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)

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

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

left = max(L)
right = min(R)
ans = right - left + 1
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() )

l_max = 0
r_min = 100000
for i in range(m):
    if l_max < l[i]:
        l_max = l[i]
    if r_min > r[i]:
        r_min = r[i]

print(r_min-l_max+1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
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)

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
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)

if min(right) < max(left):
    print(min(right) - max(left) + 1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
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)

print(min(right) - max(left) + 1)

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
min_list = []
max_list = []
for i in range(k):
    j, l = list(map(int, input().split()))
    min_list.append(j)
    max_list.append(l)

print(min(max_list) - max(min_list) + 1)

Submission status: Wrong Answer

Solution code:
temp=input().split()
N=int(temp[0])
M=int(temp[1])
Lmax=int(0)
Rmin=int(N-1)

for i in range(M):
  temp=list(map(int, input().split()))
  if Lmax<temp[0]-1:
    Lmax=temp[0]-1
    
  if Rmin>temp[1]-1:
    Rmin=temp[1]-1
    
if Rmin>Lmax:
  print(Rmin-Lmax+1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
temp=input().split()
N=int(temp[0])
M=int(temp[1])
Lmax=int(0)
Rmin=int(N-1)

for i in range(M):
  temp=list(map(int, input().split()))
  if Lmax<temp[0]-1:
    Lmax=temp[0]-1
    
  if Rmin>temp[1]-1:
    Rmin=temp[1]-1
    
if Rmin<Lmax:
  print(Rmin-Lmax+1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
temp=input().split()
N=int(temp[0])
M=int(temp[1])
Lmax=int(0)
Rmin=int(N-1)

for i in range(M):
  temp=list(map(int, input().split()))
  if Lmax<temp[0]-1:
    Lmax=temp[0]-1
    
  if Rmin>temp[1]-1:
    Rmin=temp[1]-1
    
print(Rmin-Lmax+1)

Submission status: Wrong Answer

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

a=0
b=10**5
for i in range(m):
    if l[i][0]>=a:
        a=l[i][0]
    if l[i][1]<=b:
        b=l[i][1]

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)

bottom=1
top=N

for i in range(M):
    if L[i] > bottom:
        bottom = L[i]
    if R[i] < top:
        top = R[i]

ans = top-bottom+1
print(ans)

Submission status: Wrong Answer

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

maxL = float("-inf")
minR = float("inf")

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

print(minR - maxL + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np

n,m = map(int,input().split())
count = 0
Li = []
Ri = []
for i in range(m):
  l,r = map(int,input().split())
  Li.append(l)
  Ri.append(r)
  
LM = max(Li)
RM = min(Ri)

print(RM - LM +1)

Submission status: Wrong Answer

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

keymax = 10**6
keymin = 0
for i in range(M):
	if X[i][0] > keymin:
		keymin = X[i][0]
	if X[i][1] < keymax:
		keymax = X[i][1]

print(keymax-keymin+1)

Submission status: Wrong Answer

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

lower, upper = 1, n

for _ in range(m):
    a,b=map(int,input().split())
    lower=max(lower, a)
    upper=min(upper, b)

print(upper-lower+1)

Submission status: Wrong Answer

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

lower, upper = 0, n

for _ in range(m):
    a,b=map(int,input().split())
    lower=max(lower, a)
    upper=min(upper, b)

print(upper-lower+1)

Submission status: Wrong Answer

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

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

ll = l[0]
rr = r[0]

for i in range(1,m):
    if ll < l[i]:
        ll = l[i]
    if rr > r[i]:
        rr = r[i]

cnt = rr-ll+1
if cnt >= 0:
    print(cnt)

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())
  if L < l:
    l = L
  if r < R:
    r = R
if l > r:
  print(0)
else:
  print(r-l+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(M):
    l, r = [int(x) for x in input().split(" ")]
    L.append(l - 1)
    R.append(r - 1)

L_max = max(L)
R_min = min(R)

count = R_min - L_max + 1 if R_min - L_max > 0 else 0
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ls = []
rs = []
for i in range(m):
    lr = [int(_) for _ in input().split()]
    ls.append(lr[0])
    rs.append(lr[1])

print(min(min(rs) - max(ls) + 1, 0))

Submission status: Wrong Answer

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

ls = []
rs = []
for i in range(m):
    lr = [int(_) for _ in input().split()]
    ls.append(lr[0])
    rs.append(lr[1])

print(min(rs) - max(ls) + 1)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=list(range(N))
ans,L,R=0,0,N
for i in range(M):
  Ltmp,Rtmp=map(int,input().split())
  if L<Ltmp:
    L=Ltmp
  if R>Rtmp:
    R=Rtmp
ans=R-L+1
print(ans)

Submission status: Wrong Answer

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

hoge = input().split()
n=int(hoge[0])
m=int(hoge[1])

l=[]
r=[]

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n,m=[int(i) for i in input().split()]
a=[]
for i in range(m):
    l,r=[int(i) for i in input().split()]
    a.append(set(range(l,r+1)))
if m==1:
  print(len(a))
  exit()
for i in range(m):
  a[0]=a[0] & a[1]
print(len(a))

Submission status: Wrong Answer

Solution code:
def main():

    N,M=map(int,input().split())
    #undivList=[map(int,(input().split())) for _ in range(N)]
    undivList=[]
    for _ in range(M):
        l=map(int,input().split())
        undivList +=l
    atmax=max(undivList[0::2])
    atmin=min(undivList[1::2])
    
    if atmax>atmin:
        print(0)
    else:
        print(atmax-atmin+1)



if __name__== "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():

    N,M=map(int,input().split())
    #undivList=[map(int,(input().split())) for _ in range(N)]
    undivList=[]
    for _ in range(M):
        l=map(int,input().split())
        undivList +=l
    atmax=max(undivList[0::2])
    atmin=min((i for i in undivList[1::2] if i >= atmax))

    print(abs(atmax-atmin)+1)

    


if __name__== "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():

    N,M=map(int,input().split())
    #undivList=[map(int,(input().split())) for _ in range(N)]
    undivList=[]
    for _ in range(M):
        l=map(int,input().split())
        undivList +=l
    atmax=max(undivList[0::2])
    atmin=min(undivList[1::2])
    if atmin < atmax:
      atmin=0
    print(abs(atmax-atmin)+1)

    


if __name__== "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():

    N,M=map(int,input().split())
    #undivList=[map(int,(input().split())) for _ in range(N)]
    undivList=[]
    for _ in range(M):
        l=map(int,input().split())
        undivList +=l
    print(abs(max(undivList[0::2])-min(undivList[1::2]))+1)

    


if __name__== "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N,M= map(int,input().split())
LRlis = [list(map(int, input().split())) for i in range(M)]
maxL = 0
minR = 10**5
for i in range(M):
  maxL = max(LRlis[i][0],maxL)
  minR = min(LRlis[i][1],minR)

print(minR-maxL+1)

Submission status: Wrong Answer

Solution code:
N,M= map(int,input().split())
LRlis = [list(map(int, input().split())) for i in range(M)]
print(LRlis[0][0])
A = list(range(LRlis[0][0],LRlis[0][1]+1))
for i in range(M):
  B = list(range(LRlis[i][0],LRlis[i][1]+1))
  C = list(set(A) & set(B))

print(len(C))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
c = 0
d = 10 ** 9
for i in range(b):
    e, f = map(int, input().split())
    c = max(c, e)
    d = min(d, f)
print(d-c+1 if d <= d else 0)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
c = 0
d = 10 ** 9
for i in range(b):
    e, f = map(int, input().split())
    c = max(c, e)
    d = min(d, f)
print(d-c+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)
for m in R:
    if m < max(L):
        R.remove(m)
print(min(R)-max(L)+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
min_ = 0
max_ = 100001
for i in range(m):
  li = list(map(int,input().split()))
  
  if min(li) >= min_ :
    min_ = min(li)
  if max(li) <= max_:
    max_ = max(li)
if min_ >= max_:
    print(0)
else:
    print(max_ - min_ + 1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
min_ = 0
max_ = 100001
for i in range(m):
  li = list(map(int,input().split()))
  
  if min(li) >= min_ :
    min_ = min(li)
  if max(li) <= max_:
    max_ = max(li)
    
print(max_ - min_ + 1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
min_ = 0
max_ = 100001
for i in range(m):
  li = list(map(int,input().split()))
  
  if min(li) > min_ :
    min_ = min(li)
  if max(li) < max_:
    max_ = max(li)
    
print(max_ - min_ + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for _ in range(m-1):
  templ, tempr = map(int, input().split())
  l = max(l, templ)
  r = min(r, tempr)

print(r-l+1)

Submission status: Wrong Answer

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

Lmax = 1
Rmin = N

for i in range(M):
    L,R = list(map(int, input().split()))
    Lmax = max(Lmax, L)
    Rmin = min(Rmin, R)

print(Rmin-Lmax+1)