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

ans = a[0][1]-a[-1][0]+1

print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
s,t=0,100001
for i in range(m):
    l,m=map(int,input().split())
    if l>s:
        s=l
    if m<t:
        t=m

ans=t-s+1
print(ans)

Submission status: Wrong Answer

Solution code:
#! python3
#  solve127C.py

card_num,gate_num = map(int,input().split())

ans = 0

for i in range(gate_num):
    L,R = map(int,input().split())
    if L<=card_num<=R:
        ans+=1
        
print(ans)

Submission status: Wrong Answer

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

for m in range(M):
  L,R = map(int,input().split())
  List[L-1:R] = [1 for i in range(R-L+1)]  
  List[:L-1] = [0 for i in range(L-1)]
  List[R:] = [0 for i in range(N-R)]
  print(List)
  
print(List.count(1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

L, R = map(int, input().split())
ans = set(range(L, R + 1))

for i in range(1, M):
    L, R = map(int, input().split())
    ans -= set(range(L, R + 1))

print(len(ans))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split(' '))
l = []
start = 0
end = n+1
count = 0

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

for i in l:
    if i[0] > start:
        start = i[0]
    if i[1] < end:
        end = i[1]

print(end-start+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split(' '))
l = []
start = 0
end = n
count = 0
f = False

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

for i in l:
    if i[0] >= start:
        start = i[0]
    if i[1] <= end:
        end = i[1]

print(end-start+1)

Submission status: Wrong Answer

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

low = 1
high = 10**5

for l,r in lr:
    if low <= l:
        low = l 
    if r <= high:
        high = r 

print(high - low + 1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N,M= map(int, input().split())
L,R= map(int, input().split())
flag = True
for i in range(M-1):
    a,b= map(int, input().split())
    if a >= L and b <= R:
        L = a
        R = b
    elif L <= b and R >= b:
        R = b
    elif L <= a and R >= a:
        L = a
    else:
        flag = False
        break
if flag:
 print(R-L+1)
else:
    print(0)

Submission status: Wrong Answer

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

mm=0
mx=10**5
for _ in range(M):
    l,r = map(int,input().split())
    mm = max(mm,l)
    mx= min(mx,r)
print(mx-mm+1)

Submission status: Wrong Answer

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

for _ in range(M):
    l, r = [int(a) for a in input().split()]
    L.append(l)
    R.append(r)

mingate = max(L)
maxgate = min(R)
print(maxgate - mingate + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

L = []
R = []
L_append = L.append
R_append = R.append
for l, r in LR:
    L.append(l)
    R.append(r)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
lmax=0
rmin=1000000

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L = 0
R = N
for m in range(M):
    L_new,R_new = map(int,input().split())
    if L_new > L:
        L = L_new
    if R_new < R:
        R = R_new

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

Submission status: Wrong Answer

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

st = 0
en = N

for _ in range(M):
    l, r = map(int, input().split())
    st = max(st, l)
    en = min(en, r)

print(en - st + 1)

Submission status: Wrong Answer

Solution code:
import collections
n,m = map(int,input().split())
card = [list(map(int,input().split())) for c in range(m)]
l = 0
r = n
for index,c in enumerate(card):
	if c[0] >= l:
		l = c[0]
	if c[1] <= r:
		r = c[1]
print(r-l+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
cardid_2_num_map = [0] * (10**5 + 2)

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

for i in range(1, n + 1):
    cardid_2_num_map[i] += cardid_2_num_map[i - 1]

max_sum_num = max(cardid_2_num_map)

count_max_card = cardid_2_num_map.count(max_sum_num)
in_a_low_value = 0

flag = False
for i in range(n + 2):
    if cardid_2_num_map[i] == max_sum_num:
        in_a_low_value += 1
        flag = True
    elif flag:
        break

if in_a_low_value == count_max_card:
    print(in_a_low_value)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
cardid_2_num_map = [0] * (10**5 + 2)

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

for i in range(1, n + 1):
    cardid_2_num_map[i] += cardid_2_num_map[i - 1]

max_sum_num = max(cardid_2_num_map)

count_max_card = cardid_2_num_map.count(max_sum_num)
in_a_low_value = 0

for i in range(n + 2):
    if cardid_2_num_map[i] == max_sum_num:
        in_a_low_value += 1

if in_a_low_value == count_max_card:
    print(in_a_low_value)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
cardid_2_num_map = [0] * (10**5 + 2)

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

for i in range(1, n + 1):
    cardid_2_num_map[i] += cardid_2_num_map[i - 1]

max_sum_num = max(cardid_2_num_map)
# print(cardid_2_num_map[:10])
print(cardid_2_num_map.count(max_sum_num))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

Submission status: Wrong Answer

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

ans_1=max(l_list)
ans_2=min(r_list)
print(ans_2-ans_1+1)

Submission status: Wrong Answer

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

left = 1
right = n+1

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

print(right-left+1)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
a = []
b = []
for i in range(M):
    L, R = map(int,input().split())
    a.append(L)
    b.append(R)
a = sorted(a)
b = sorted(b)
A = a[M - 1]
B = b[0]
print(B - A + 1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

min_l = 0
max_l = 10**6

for _ in range(m):
    L, R = map(int, input().split())
    min_l = max(min_l, L)
    max_l = min(max_l, R)

print(max_l - min_l + 1)

Submission status: Wrong Answer

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

min = lst[0][0]
max = lst[0][1]
for v in lst:
    if v[0] > min:
        min = v[0]
    if v[1] < max:
        max = v[1]
print(max-min + 1)

Submission status: Wrong Answer

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

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

if r_min > l_max:
    print(0)
else:
    print(r_min-l_max+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

N,M=input2()
L,R=[],[]
for i in range(M):
	l,r=input2()
	L.append(l)
	R.append(r)

MIN=0
MAX=N

for j in range(M):
	if L[j]>MIN:
		MIN=L[j]
	if R[j]<MAX:
		MAX=R[j]

print((MAX-MIN)+1)

Submission status: Wrong Answer

Solution code:
def resolve():
    #n=int(input())
    #a,b=map(int,input().split())
    #x=list(map(int,input().split()))
    #a=[list(map(lambda x:int(x)%2,input().split())) for _ in range(h)]
    n,m=map(int,input().split())
    lr=sorted([list(map(int,input().split())) for _ in range(m)])
    mr=10**6
    for i in range(m):
        mr=min(mr,lr[i][1])
    print(max(0,mr-lr[0][0]))

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
right = 10**5
left = 0
for _ in range(M):
  a,b = map(int,input().split())
  right = min(right,b) 
  left = max(left,a)

print(right-left+1)

Submission status: Wrong Answer

Solution code:
import itertools
n,m = map(int,input().split())
card = [list(map(int,input().split())) for c in range(m)]
ans = 0
tmp = []
if m == 1:
    print(max(card[0]))
else:
    for c in card:
      c = [i for i in range(c[0],c[-1]+1)]
      tmp.append(c)

    tmp = list(itertools.chain.from_iterable(tmp))
    tmp = [x for x in set(tmp) if tmp.count(x) >= m]

    print(len(tmp))

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M=map(int,input().strip().split())
LR=np.array([list(map(int,input().strip().split())) for _ in range(M)])
print(min(LR[:,1])-max(LR[:,0])+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
arr = []
for i in range(m):
  l, r = map(int, input().split())
  arr.append([l, l + 1, r])
ans = 0
for i in range(n):
  f = 0
  for j in range(m): 
    if i + 1 in arr[j]:
      next
    else:
      f = 1
      break
  if f == 0:
    ans += 1
if m == 1:
  ans = n
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = input().split(' ')
N = int(N)
M = int(M)
min = 1
max = N
for i in range(M):
  l, m = input().split(' ')
  l = int(l)
  m = int(m)
  if min>m or max<l:
    print(0)
    break 
  if min < l:
    min = l
  if max > m:
    max = m
print(max-min+1)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    L = 0
    R = 10 ** 5 + 1

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

    print(R-L+1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
ll=sum(l,[])
max_=max(ll[::2])
min_=min(ll[1::2])
print(min_-max_+1)

Submission status: Wrong Answer

Solution code:
#36
N,M = map(int,input().split())
li = []
ri = []
num = 0


for i in range(M):
    L,R = map(int,input().split())
    li.append(L)
    ri.append(R)
L = max(li)
R = min(ri)
num = R-L+1
    
print(num)

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()))
  L.append(tmp[0])
  R.append(tmp[1])

lower = max(L)
upper = min(R)
print(abs(upper-lower)+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()))
  L.append(tmp[0])
  R.append(tmp[1])

lower = max(L)
upper = min(R)
print(upper-lower+1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L_max,R_min = 0,10000000
for i in range(M):
  L,R = map(int,input().split())
  L_max = max(L_max,L)
  R_min = min(R_min,R)
print(R_min - L_max + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

L_max=0
R_min=10**6
for i in range(m):
    if gate[i][0]>L_max:
        L_max=gate[i][0]

for i in range(m):
    if gate[i][1]<R_min:
        R_min=gate[i][1]


print(R_min-L_max+1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 12, 2020 15:41:56 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


def main():
  N, M = list(map(int, input().split()))

  min_ = -float('inf')
  max_ = float('inf')
  for _ in range(M):
    L, R = map(int, input().split())
    min_ = max(min_, L)
    max_ = min(max_, R)

  print(max_ - min_ + 1)


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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
k = [list(map(int,input().split())) for i in range(m)]
l,r = [list(i) for i in zip(*k)]

x = m
y = min(r)

p = 0
for i in range(1,n+1):
    if x <= i and i <= y:
        p += 1

print(p)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
data=input().split()
N=int(data[0])
M=int(data[1])
data_gate=[input().split() for i in range(M)]
data_min=[]
data_max=[]
for i in range(M):
    data_min.append(int(data_gate[i][0]))
    data_max.append(int(data_gate[i][1]))
m=max(data_min)
M=min(data_max)
ans=M-m+1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    L, R = 1, n
    for _ in range(m):
        l, m = map(int, input().split())
        if l > L: L = l
        if m < R: R = m
    print(R-L+1)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    L, R = 0, n+1
    for _ in range(m):
        l, m = map(int, input().split())
        if l > L: L = l
        if m < R: R = m
    print(R-L+1)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
a=-float("inf")
b=float("inf")
for i in range(m):
    l,r=mp()
    a=max(a,l)
    b=min(b,r)
print(b-a+1)

Submission status: Wrong Answer

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

for _ in range(m):
    s, t = map(int, input().split())
    l.append(int(s))
    r.append(int(t))

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
(n, m,), *g = [[*map(int, i.split())] for i in open(0)]
ma = n
mi = 0
for l, r in g:
    mi = max(mi, l)
    ma = min(ma, r)

print(ma - mi + 1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = 1
r = 10**5
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:
import numpy as np

i = list(map(int, input().split()))
N = i[0]
M = i[1]

l = np.array([list(map(int, input().split())) for i in range(M)])

limit1 = max(l[:, 0])
limit2 = min(l[:, 1])

print(limit2 - limit1 + 1)

Submission status: Wrong Answer

Solution code:
#n=int(input())
#s,t=input().split()
n,m = map(int, input().split())
#l=list(map(int, input().split()))
l=[0]*100005
r=[1000005]*100005
z=1000010
for i in range(m):
   l[i],r[i]=map(int,input().split()) 
mi=max(l)
ma=min(r)




print(ma-mi+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans,ansf = 1,n

for i in range(m):
    l,r = map(int,input().split())
    ans = max(ans,l)
    ansf = min(ansf,r)
    
print(ansf-ans+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

print(R-L+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n, m = [int(w) for w in input().split()]

m_l = 0
m_r = n
for i in range(m):
    l, r = [int(w) for w in input().split()]
    m_l = max(m_l, l)
    m_r = min(m_r, r)
print(m_r-m_l+1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
min_L = 1
max_R = 1 * 10 ** 5
for i in range(M):
    L,R=map(int,input().split())
    min_L = max(L,min_L)
    max_R = min(R,max_R)

if max_R > min_L :  
    print(max_R - min_L + 1)
else :
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M=list(map(int,input().split()))
l=1
r=N
for m in range(M):
    l_,r_ = list(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 = map(int,input().split())
L = [0] * (M)
R = [0] * (M)
for i in range(M):
    L[i],R[i] = map(int,input().split())
count = 0
m = [ [0 for j in range(M+1)] for i in range(M)]
for i in range(M):
    for j in range(i+1):
        m[i][j] = R[j]
    for k in range(i,M):
        m[i][k+1] = L[k]
        
for i in range(1,N+1):
    flag = 1
    for j in range(M):
        if i in m[j]:
            pass
        else:
            flag = 0
            break
    if flag == 1:
        count += 1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
ans=0
a,b=map(int,input().split())
W=[]
for i in range(b):
  s,t=map(int,input().split())
  for k in range(s,t+1):
    W.append(k)
for d in range(len(W)+1):
  V=W.count(d)
  if V==b:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
ans=0
a,b=map(int,input().split())
W=[]
for i in range(b):
  s,t=map(int,input().split())
  for k in range(s,t+1):
    W.append(k)
for d in range(len(W)+1):
  V=W.count(d)
  if V==b:
    ans+=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

left = 1
right = N

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

print(right - left + 1)

Submission status: Wrong Answer

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

left = 0
right = float('inf')
for i in range(m):
    l, r = map(int, input().split())
    left = max(left, l)
    right = min(right, r)
    
print(right - left + 1)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
max_l = float("-inf")
min_r = float("inf")
for _ in range(m):
  l,r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
if l <= r:
  print(min_r - max_l + 1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
max_l = float("-inf")
min_r = float("inf")
for _ in range(m):
  l,r = map(int, 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:
n,m=map(int,input().split())
##かーどについての初期配列
head =0
tail = n
for i in range(m):
    l,r = map(int,input().split())
    head = max(head,l)
    tail = min(r,tail)
    
print(tail-head+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
low = 0
high = 100001

for i in range(m):
  l,m = map(int, input().split())
  low = max(low, l)
  high = min(high, m)
print(min(high-low+1, n))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline

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

ansl=-1
ansr=10**6

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

print(ansr-ansl+1)

Submission status: Wrong Answer

Solution code:
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])

card = [i+1 for i in range(N)]

mi = 0
ma = N

for j in range(M):
    i = input().split(" ")
    l = int(i[0])
    r = int(i[1])
    if l in card:
      lindex = card.index(l)
      del card[:lindex]
    if r in card:
      rindex = card.index(r) + 1
      del card[rindex:]

print(len(card))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

L = []; R = []
for _ 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
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
gate=[list(map(int,input().split())) for i in range(m)]
small=[]
tall=[]
for i in range(m):
    small+=[gate[i][0]]
    tall+=[gate[i][1]]
smallmax=(max(small))
tallmin=(min(tall))
if tallmin-smallmax>0:
    print(tallmin-smallmax+1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
gate=[list(map(int,input().split())) for i in range(m)]
small=[]
tall=[]
for i in range(m):
    small+=[gate[i][0]]
    tall+=[gate[i][1]]
smallmax=(max(small))
tallmin=(min(tall))
print(tallmin-smallmax+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans = min_r - max_l + 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
L=[]
M=[]
for i in range(m):
  l,m=map(int,input().split())
  L.append(l)
  M.append(m)
  
a=max(L)
b=min(M)
if a<b:
  print(b-a+1)
else:
  print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if min(R) <= max(L):
  print(min(R)-max(L)+1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
L = []
R = []
for _ 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):
  ln, rn = map(int, input().split())
  l.append(ln)
  r.append(rn)
  
lmax = max(l)
rmin = min(r)

ans = rmin - lmax + 1

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n,m=map(int,input().split())
    l=-1
    r=10**5+1
    for _ in range(m):
        l2,r2=map(int,input().split())
        l=max(l,l2)
        r=min(r,r2)
    print(min(r,n)-l+1)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
ok = [0, pow(10, 5)]

for i in range(M):
    l, r = map(int, input().split())
    if l >= ok[0]:
        ok[0] = l
    if r <= ok [1]:
        ok[1] = r
print(ok[1] - ok[0] +1)

Submission status: Wrong Answer

Solution code:
# 範囲の幅を狭めていく

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

# 初期条件
left = 1
right = n

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

print(right-left+1)

Submission status: Wrong Answer

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

in_min = 1
in_max = N

for i in range(M):
	l, r = map(int, input().split())
	# 最小値(今の最小値と取得値のうち、大きいほう)
	in_min = max([in_min, l])
	# 最大値(今の最大値と取得値のうち、小さいほう)
	in_max = min([in_max, r])

# 個数を出力
cnt = in_max - in_min +1
print(cnt)