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:
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

############
############
############

N, M = l_inpl()
D = [0] * (N+1)
for _ in range(M):
    li, ri = l_inpl()
    li, ri = li-1, ri-1
    D[li] += 1
    D[ri+1] -= 1

for i in range(1, len(D)):
    D[i] += D[i-1]

ans_l = D[:len(D)-1]
print(ans_l.count(max(ans_l)))

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
rl = 0
rr = n + 1
for _ in range(m):
    l,r = map(int, input().split())
    r += 1

    if r<=rl or rr<=l:
        rl = n+1
        rr = n+1
        continue
    
    if rl<=l and r<=rr:
        rl = l
        rr =r
    elif l<=rl and rr<=r:
        continue
    elif l<rr:
        rl = l
    else:
        rr = r

print(rr-rl)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M =map(int,input().split())
L = 0
R = N
for i in range(M):
  Lnew, Rnew =map(int,input().split())
  if(L < Lnew):
    L = Lnew
  if(R > Rnew):
    R = Rnew

print(R-L+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
la, ra = map(int, input().split())
for i in range(1, m):
    lm, rm = map(int, input().split())
    overlap = False
    if la <= lm <= ra:
        la = lm
        overlap = True
    if la <= rm <= ra:
        ra = rm
        overlap = False
    if not overlap:
        print(0)
        exit(0)

print(ra - la + 1)

Submission status: Wrong Answer

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


def main():
    n, m = map(int, input().split())
    lmax = 0
    rmin = float('inf')

    for i in range(m):
        li, ri = map(int, input().split())
        lmax = max(lmax, li)
        rmin = min(rmin, ri)

    print(rmin - lmax + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

l_list = list()
r_list = list()
for _ in range(m):
  l, r = map(int, input().split())
  l_list.append(l)
  r_list.append(r)
  
ll = max(l_list)
rr = min(r_list)
print(rr-ll+1)

Submission status: Wrong Answer

Solution code:


N,M=[int(c) for c in input().split()]
Lmax=0
Rmin=1e5
for i in range(M):
	L,R=[int(c) for c in input().split()]
	if(L>Lmax):
		Lmax=L
	if(R<Rmin):
		Rmin=R

if(N>Rmin):
	print(Rmin-Lmax+1)
elif(Lmax<=N):
	print(N-Lmax+1)
else:
	print(0) 
#LmaxとRminの間に入っているのがいくつなのか

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
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)

m = max(R)
imo = [0] * (m+2)
for l,r in zip(L,R):
    imo[l] += 1
    imo[r+1] -= 1
imo = list(accumulate(imo))

print(imo.count(max(imo)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

lmax = 0
rmin = 1000000

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

print(rmin-lmax+1)

Submission status: Wrong Answer

Solution code:
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

N, M = [int(x) for x in input().split()]

maxL = 0
minR = 10 ** 5

for _ in range(M):
    L, R = [int(x) for x in input().split()]
    maxL = max(maxL, L)
    minR = min(minR, R)

print(minR - maxL + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,M=MAP()

imos=[0]*(N+1)
for i in range(M):
    l,r=MAP()
    imos[l-1]+=1
    imos[r]-=1

acc=list(accumulate(imos))

mx=max(acc)
print(acc.count(mx))

Submission status: Wrong Answer

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

right = N
left = 0

for i in e:
    if left < i[0]:
        left = i[0]
    if right > i[1]:
        right = i[1]
if right >= left:
    print(right - left)
else:
    print("0")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Lmax = max([L for L, _ in ids])
Rmin = min([R for _, R in ids])

print(Rmin-Lmax+1)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().strip().split(' ')]

L, R = [int(i) for i in input().strip().split(' ')]
for _ in range(M - 1):
  l, r = [int(i) for i in input().strip().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,R = 1,N
for i in range(M):
  Lx,Rx = map(int,input().split())
  if Lx>L:L=Lx
  if Rx<R:R=Rx
print(R-L+1)

Submission status: Wrong Answer

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

ll = 0
rr = int(10e5+1)
for _ 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 = map(int, input().split())
l = [0] * m
r = [0] * m
for i in range(m):
    l[i], r[i] = map(int, input().split())

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
lr_list = [list(map(int, input().split())) for _ in range(m)]
max_l = 1
min_r = n
for lr in lr_list:
    max_l = max(max_l, lr[0])
    min_r = min(min_r, lr[1])
print(min_r - max_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):
    newL,newR=map(int,input().split())
    L,R=max(L,newL),min(R,newR)
print(R-L+1)

Submission status: Wrong Answer

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

L = []
for i in range(m):
    l, r = map(int, input().split())
    L.append((l, r))
    
ans_min = 0
ans_max = 10 ** 5
for i in L:
    ans_min = max(i[0], ans_min)
    ans_max = min(i[1], ans_max)
    
print(min(ans_max-ans_min+1, n))

Submission status: Wrong Answer

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

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


ans=0
Gates=[0]*(N+2)

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

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

for i in Gates:
    if i==M:
        ans+=1

print(ans)

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 = 0
r = n
for i 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())
Ls = []
Rs = []
for _ in range(M):
    L, R = map(int, input().split())
    Ls.append(L)
    Rs.append(R+1)
L_max = max(Ls)
R_min = min(Rs)
print(R_min - L_max)

Submission status: Wrong Answer

Solution code:
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
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 SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

N, M = LI()
L, R = [], []
for i in range(M):
    x, y = LI()
    L.append(x)
    R.append(y)

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
Lmax = -1
Rmin = N + 1

for _ 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())
mi = 999999
ma = 0
for i in range(m):
    l, r = map(int, input().split())
    ma = max(l, ma)
    mi = min(r, mi)
print(str(int(mi - ma) + 1))

Submission status: Wrong Answer

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

l, r = 0, float("inf")
for lr in lrList:
    l, r = max(lr[0], l), min(lr[1], r)

ans = min(r, N) - l + 1
print(ans)

Submission status: Wrong Answer

Solution code:
l = raw_input().split()
N = int(l[0])
M = int(l[1])

L = []
R = []

for i in range(M):
    l = raw_input().split()
    L.append(int(l[0]))
    R.append(int(l[1]))

print(R[0] - L[M - 1] + 1)

Submission status: Wrong Answer

Solution code:
import math
N,M = list(map(int,input().split(" ")))
ll = -10e9
rr = (10e9)
for i in range(M):
    l,r = list(map(int, input().split(" ")))
    if l > ll:
        ll = l
    if r  <  rr :
        rr = r
print(rr - ll + 1)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
min=0
max=1e+6
for i in range(M):
    L,R=map(int,input().split())
    if(min<L):
        min=L
    if(max>R):
        max=R
        

print(max-min+1)

Submission status: Wrong Answer

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

for n in range(M):
    L[n],R[n] = map(int,input().split())

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

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
l_ans = 1
r_ans = N
for i in range(M):
    L,R = map(int, input().split())
    if L > l_ans:
        l_ans = L
    if R < r_ans:
        r_ans = R
print(r_ans - l_ans + 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())
a = 10**6
b = 0
for i in range(M):
    L, R = map(int, input().split())
    b = L if L>b else b
    a = R if R<a else a
print(a-b+1)

Submission status: Wrong Answer

Solution code:

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

p=0
q=100000000000000

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


class Solution:
    def main(self):
        N, M = map(int, input().split())
        L = []
        R = []
        cards = set(list(range(1, N+1)))
        left = 1
        right = N
        for _ in range(M):
            l, r = map(int, input().split())
            left = max(left, l)
            right = min(right, r)
        print(right-left+1)


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

Submission status: Wrong Answer

Solution code:
from itertools import product
import bisect
import sys


def input():
    return sys.stdin.readline()[:-1]

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = [1, n]
for _ in range(m):
  a, b = map(int, input().split())
  if a > l[0]:
    l[0] = a
  if b < l[1]:
    l[1] = b

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

Submission status: Wrong Answer

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

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

minimum, maximum = 0, N+1

for i in range(M):
    L, R = list(map(int, input().split()))
    if minimum < L:
        minimum = L
    if R < maximum:
        maximum = R

print(maximum-minimum+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
max_l = 0
min_r = 10**5
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
if ans < 0:
    ans = 0
print(min(min_r - max_l + 1, n))

Submission status: Wrong Answer

Solution code:
n,m=[int(x) for x in input().split()]
first_gate=0
last_gate=10**10
for _ in [0]*m:
    small,large=[int(x) for x in input().split()]
    first_gate=max(first_gate,small)
    last_gate=min(last_gate,large)
print(last_gate- first_gate+1)

Submission status: Wrong Answer

Solution code:
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
L = 1
R = N
for _ in range(M):
    Li, Ri = inpl()
    if Li > L:
        L = Li
    if Ri < R:
        R = Ri
print(R-L+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(M)]
left, right = 0, 10**6

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

Submission status: Wrong Answer

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

ll = 1
rr = N

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 = map(int, input().split())
la, ra = map(int, input().split())
for i in range(1, m):
    lm, rm = map(int, input().split())
    if la <= lm <= ra:
        la = lm
    if la <= rm <= ra:
        ra = rm

print(ra - la + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(R-L+1)

Submission status: Wrong Answer

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

s = 0
e = n-1

for _ in range(m):
  l,r = map(int,input().split())
  
  s = max(s,l)
  e = min(e,r)
  
print(max(e-s+1,0))

Submission status: Wrong Answer

Solution code:
n,m=[int(_) for _ in input().split()]
ld=1
rd=n
for iii in range(m):
  l,r=[int(_) for _ in input().split()]
  if ld<l:
    ld=l
  if rd>r:
    rd=r

print(rd-ld+1)

Submission status: Wrong Answer

Solution code:
N,M=(int(x) for x in input().split())
mx=0
mn=10**5+1
for i in range(M):
    L,R=(int(x) for x in input().split())
    mn=min(R,mn)
    mx=max(L,mx)

print(mn-mx+1)

Submission status: Wrong Answer

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

max_l = 1
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)

print(min_r - max_l + 1)

Submission status: Wrong Answer

Solution code:
n, M, *X = map(int, open(0).read().split())
print(min(X[1::2]) - max(X[::2]) + 1)

Submission status: Wrong Answer

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

for i in range(m):
    li, ri = [int(i) for i in input().split(" ")]
    if l < li:
        l = li
    if ri < r:
        r = ri

print(r - l + 1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(M)]
maxx = 100000
minn = 0

for l, r in lr:
    minn = max(l, minn)
    maxx = min(r, maxx)

print(maxx - minn + 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())
    if left < l:
        left = l
    if r < right:
        right = r
print(str(right-left+1))

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-=1
    r-=1
    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 = []
R = []
for i in range(m):
    li, ri = map(int, input().split())
    L.append(li)
    R.append(ri)
print(min(R)-max(L)+1)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in raw_input ().split()]
X, Y = 0, 10 ** 6
for i in range(M):
    x, y = [int(i) for i in raw_input ().split()]
    X = max(X, x)
    Y = min(Y, y)
print Y - X + 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

L = []
for i in range(m):
    l, r = map(int, input().split())
    L.append((l, r))
    
ans_min = 0
ans_max = 10 ** 5
for i in L:
    ans_min = max(i[0], ans_min)
    ans_max = min(i[1], ans_max)
    
print(ans_max-ans_min+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
Min = 0
Max = N
for m in range(M):
    L, R = map(int, input().split())
    Min = max(Min, L)
    Max = min(Max, R)
print(Max-Min+1)

Submission status: Wrong Answer

Solution code:
N,M=map(int ,raw_input().split())
S = 1
E = N
for i in range(M):
    L,R=map(int ,raw_input().split())
    if S<L:
        S=L
    if E>R:
        E=R
if E<=S:
    print(str(0))
else:
    print(str(E-S))

Submission status: Wrong Answer

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


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    lm = max(L)
    rm = min(R)
    print(rm-lm+1)

    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L,R = 1,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:
import math
from functools import reduce
from collections import deque

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,m = get_nums_l()

l_max = 0
r_min = n
for i in range(m):
    l,r = get_nums_l()
    if l_max < l:
        l_max = l
    if r_min > r:
        r_min = r

print(r_min - l_max + 1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,m = input().split()
n = int(n)
m = int(m)
l = 0
r = n+1
for i in range(m):
    l2,r2 = input().split()
    l2 = int(l2)
    r2 = int(r2)
    if l2 > l:
        l = l2
    if r2 < r:
        r = r2
print(r-l+1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def solve(): 
    N, M =  map(int, input().split())
    l = 1
    r = N
    for _ in range(M):
        L, R = map(int, input().split())
        l = max(l, L)
        r = min(r, R)
    res = r-l+1
    return str(res)

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

Submission status: Wrong Answer

Solution code:
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_3.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))

    # write code
    maxL = max(L)
    minR = min(R)
    print(min(minR-maxL+1, 0))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import defaultdict
from functools import reduce

# s = input()
# n = int(input())
# A = list(map(int, input().split()))
n, m = map(int, input().split())

l = 0
r = n+1

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

print(r-l+1)

Submission status: Wrong Answer

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

a=[list(map(int,input().split())) for i in range(M)]
a1=[a[i][0] for i in range(M)]
a2=[a[i][1] for i in range(M)]

print(min(a2)-max(a1)+1)

Submission status: Wrong Answer

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

import sys
input = sys.stdin.readline
lmax,rmin = 1,N

for i in range(M):
  l,r = list(map(int,input().split()))
  if l > lmax:
    lmax = l
  if r < rmin:
    rmin = r

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

Submission status: Wrong Answer

Solution code:
N, M = tuple([int(x) for x in input().split(' ')])

minN = 1
maxN = N
for i in range(M):
    L, R = tuple([int(x) for x in input().split(' ')])
    minN = max(L, minN)
    maxN = min(R, maxN)
print(maxN-minN+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    print(min(R)-max(L)+1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    print(min(R) - max(L) + 1)


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    if left < l:
        left = l
    if right > r:
        right = r

print(right-left+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 = 0
r = 10 ** 18
for i in range(m):
    if l < s[i][0]:
        l = s[i][0]
    if s[i][1] < r:
        r = s[i][1]

print(r-l+1)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
a = -float('inf')
b = float('inf')
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())
R=10**5
L=0
for i in range(M):
    l,r=map(int,input().split())
    L=max(L,l)
    R=min(R,r)
print(R-L+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
mi=1
mx=n
for i in range(m):
    a,b=map(int, input().split())
    mi=max(a,mi)
    mx=min(mx,b)
print(mx-mi+1)

Submission status: Wrong Answer

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

low = 1
high = n

for i in range(0,m):
    low = max(low,gate[i][0])
    high = min(high,gate[i][1])

print(high-low+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
p,P=map(int,input().split())
for i in range(m-1):
  a,b=map(int,input().split())
  if p<a:
    p=a
  if b<P:
    P=b
print(P-p+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

min = 1
max = N
for i in range(M):
    L,R = map(lambda x: int(x),input().split())
    if min<L:
        min = L
    if max>R:
        max = R

print(max-min+1)

Submission status: Wrong Answer

Solution code:
N,M=[int(a) for a in input().split()]
LR=[[int(a) for a in input().split()] for _ in range(M)]
L1,R1=-10**10,10**10
for L, R in LR:
    L1 = max(L1, L)
    R1 = min(R1, R)
print(R1-L1+1)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N,M = [int(x) for x in input().split()]
LR = [[int(x) for x in input().split()]for _ in range(M)]
max_l = max(LR,key = itemgetter(0))[0]
min_r = min(LR,key = itemgetter(0))[1]
print(max(min_r-max_l+1,0))

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
# a=int(input())
lmax=0
rmin=1000000
for i in range(b):
    l,r = map(int,input().split())
    if l >= lmax:
        lmax = l
    if r <= rmin:
        rmin = r
print(rmin-lmax+1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    maxl = -float('inf')
    minr = float('inf')
    for l, r in zip(L, R):
        maxl = max(l, maxl)
        minr = min(r, minr)
    return minr - maxl + 1


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]" 
    R = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    result = solve(N, M, L, R)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()