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

start, end = 1, n
for i in range(m):
  l, r = map(int, input().split())
  if r < start or l > end:
    start = end = 0
    break
  elif l <= start and start <= r <= end:
    end = r
  elif start <= l <= end and end <= r:
    start = l
  else:
    start, end = l, r

print(end - start + 1)

Submission status: Wrong Answer

Solution code:
ss=input().split(" ")
N=int(ss[0])
M=int(ss[1])
x=1
y=N
for i in range(M):
  tt=input().split(" ")
  if int(tt[0])>x:
    x=int(tt[0])
  if int(tt[1])<y:
    y=int(tt[1])
print(int(y-x+1))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
ls = np.empty(M)
rs = np.empty(M)


for i in range(M):
    l, r = map(int, input().split())
    ls[i] = l
    rs[i] = r

if 1 <= np.min(rs) - np.max(ls):
    print(int(np.min(rs) - np.max(ls) + 1))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]

gates = [list(map(lambda x: int(x), input().split())) for i in range(m)]

first_max = 0
second_min = 100001
for gate in gates:
  first_max = max(first_max, gate[0])
  second_min = min(second_min, gate[1])

answer = second_min - first_max + 1
print(answer)

Submission status: Wrong Answer

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

l =[]
r =[]
for i in range(m):
    l1, r1 = [int(i) for i in input().split()]
    l.append(l1)
    r.append(r1)

min = -1
max = 1000000
for i in range(m):
    if  min <= l[i] <= max:
        min = l[i]
    if  min <= r[i] <= max:
        max = r[i]

print(max-min+1)

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    for m in range(M):
        L, R = map(int, input().split())
        ok_thisgate = [i for i in range(L, R+1)]
        if m == 0:
            ok = ok_thisgate
            continue
        for card in ok:
            if card in ok_thisgate:
                pass
            else:
                ok.remove(card)
    print(len(ok))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

count = min(R) - max(L) + 1
  
print('%d' % count)

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
L_max = 0
R_min = N
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

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

Submission status: Wrong Answer

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

result = 0
List = []
for i in range(M):
    L,R=map(int, input().split())
    for j in range(N):
        if L<=j+1<=R:
            result+=1
    List.append(result)
print(len(List))

Submission status: Wrong Answer

Solution code:
def main():
    N,M = map(int, input().split())
    lr = []
    for _ in range(M):
        l,r = map(int, input().split())
        lr.append((l,r))
    lr = sorted(lr, key=lambda x: x[1])
    print(lr[0][1] - lr[-1][0] + 1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

L, R = map(int, input().split())

for i in range(1, M):
    hoge, fuga = map(int, input().split())
    L = max(L, hoge)
    R = min(R, fuga)

print(R-L+1)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
max_l = 0
min_r = 100000
for _ in range(m):
    l, r = list(map(int, input().split()))
    if l > max_l:
        max_l = l
    if r < min_r:
        min_r = r
ans = min_r - max_l
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

L_max = 0
R_min = 100000

for i in range(M):
    L, R = map(int,input().split())
    if L_max < L:
        L_max = L
    if R_min > R:
        R_min = R
        
print(R_min-L_max+1)

Submission status: Wrong Answer

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

for i in range(N):
    if (0 < i):
        t[i] += t[i-1]

t = t[:-1]
m = max(t)
print(t.count(m))

Submission status: Wrong Answer

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


def main():
    from itertools import accumulate

    n, m = map(int, input().split())
    imos = [0 for _ in range(n + 1)]

    for i in range(m):
        li, ri = map(int, input().split())
        imos[li - 1] = 1
        imos[ri] = -1

    count = 0

    for i in list(accumulate(imos)):
        if i >= m:
            count += 1

    print(count)


if __name__ == '__main__':
    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())

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
ls_a = []
ls_b = []
for p in range(M):
    L,M  = map(int,input().split())
    ls_a.append(L)
    ls_b.append(M)
print(min(ls_b)-max(ls_a)+1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n, m = [int(x) for x in input().rstrip().split(" ")]

l_r_list = []

for i in range(m):
    fields = input().rstrip().split(" ")
    l_r_list.append([int(x) for x in fields])

result_range = set()

for l_r in l_r_list:
    testing = range(l_r[0], l_r[1] + 1)
    if len(result_range) == 0:
        for i in testing:
            result_range.add(i)
        continue
    result_range = result_range.intersection(testing)

print(len(result_range))

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 L > left :
        left = L
    if R < right:
        right = R

print(left-right+1)

Submission status: Wrong Answer

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

for i in range(m):
    l,r=map(int,input().split())
    if lm<l:
        lm=l
    if rm>r:
        rm=r+1

print(rm-lm)

Submission status: Wrong Answer

Solution code:
#python 3.5.2

N, M = [int(i) for i in input().split()]
LRs = [[int(j) for j in input().split()] for i in range(M)]
LRs = list(map(list, zip(*LRs)))  # 転置
Lmax = max(LRs[0])
Rmin = min(LRs[1])
Rmin = min(Rmin, N)
print(Rmin - Lmax + 1)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
max_l = 0
min_r = 100000
for _ in range(m):
    l, r = list(map(int, input().split()))
    if l > max_l:
        max_l = l
    if r < min_r:
        min_r = r
ans = min_r - max_l + 1
print(ans)

Submission status: Wrong Answer

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

import math

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

s = 0
t = 10**5+1
for i in range(m):
    a,b = list(map(int,input().split(" ")))
    if s < a:
        s = a
    if b < t:
        t = b
print(t-s+1)

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([L,R])
anslist = [list[0][0],list[0][1]]
arukadouka = True
cnt = 0
for i in range(M-1):
    if arukadouka == True:
        if anslist[0] > list[i+1][1]:
            arukadouka = False
        elif anslist[1] < list[i+1][0]:
            arukadouka = False
        else:
            if (anslist[0]<=list[i+1][0]) and (anslist[1]<=list[i+1][1]):
                anslist[0] = list[i+1][0]
            if (anslist[0]<=list[i+1][0]) and (anslist[1]>=list[i+1][1]):
                anslist[0] = list[i+1][0]
                anslist[1] = list[i+1][1]
            if (anslist[0]>=list[i+1][0]) and (anslist[1]<=list[i+1][1]):
                pass
            if (anslist[0]>=list[i+1][0]) and (anslist[1]>=list[i+1][1]):
                anslist[1] = list[i+1][1]
        cnt += 1
print(anslist[1]-anslist[0]+1)

Submission status: Wrong Answer

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

gate = []

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


for i in range(M-1):
    tmpl, tmpr = map(int, input().split())
    if l < tmpl:
        l = tmpl
    if tmpr < r:
        r = tmpr

print(r - l + 1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(' '))
left = float('-inf')
right = float('inf')
for i in range(M):
  L,R = map(int,input().split(' '))
  if left <= L:
    left = L
  if R <= right:
    right = R
  if (R-L) <= 0:
    print(0)
    exit()
print(right-left+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
#        print('L ' + str(L))
    if r < R:
        R = r
#        print('R ' + str(R))
        
print(R - L + 1)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
# sample code

v = list(map(int, input().split()))
n, m = v[0], v[1]

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

min = 1
max = n
for i in range(m):
	if l[i] > min:
		min = l[i]
	if max > r[i]:
		max = r[i]

num = max-min+1
print(num)

Submission status: Wrong Answer

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

Lmax = 0
Rmin = 100000
for i in range(m):
	L,R = map(int,input().split())
	if Lmax < L:
		Lmax = L
	if Rmin > R:
		Rmin = R

print("%d" % (Rmin - Lmax +1))

Submission status: Wrong Answer

Solution code:
ss=input().split(" ")
N=int(ss[0])
M=int(ss[1])
x=0
y=N
for i in range(M):
  tt=input().split(" ")
  if int(tt[0])>x:
    x=int(tt[0])
  if int(tt[1])<y:
    y=int(tt[1])
print(int(y-x+1))

Submission status: Wrong Answer

Solution code:
_, m = map(int, input().split())
segs = [tuple(map(int, input().split())) for _ in range(m)]
left, right = segs[0]
for l, r in segs[1:]:
    left = max(left, l)
    right = min(right, r)
print(right - left + 1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
# L = [int(x) for x in input().split()]
N, M = map(int, input().split())
# S = input()

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

ans = 0
tmp = 0
for i in range(1, N + 1):
    tmp += ok[i]
    
    if tmp == M:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

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

    L = []
    R = []
    id = list(range(N+1))
    id_set = set(id)
    for _ in range(M):
        l, r = list(map(int, input().split()))
        L.append(l)
        R.append(r)

    max_l = max(L)
    min_r = min(R)
    print(min_r - max_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)]

l0 = L[0][0]
l1 = L[0][1]
for i in L:
    if l0 < i[0]:
        l0 = i[0]

    if l1 > i[1]:
        l1 = i[1]

print(l1 - l0 + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
n, m = map(int, input().split())

card = set(range(1, n+1))

card

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


gate = np.array(gate)

l = gate[:, 0].max()
r = gate[:, 1].min()

print(r+1 - l)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
ls = np.empty(M)
rs = np.empty(M)


for i in range(M):
    l, r = map(int, input().split())
    ls[i] = l
    rs[i] = r


print(int(np.min(rs) - np.max(ls) + 1))

Submission status: Wrong Answer

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

    ans = f(N, M, lr)
    #ans = TLE(N, M, lr)
    print(ans)


def f(N, M, lr):
    """
    区間、累積和？
    2分探索？
    """
    import numpy as np
    a = np.zeros(N, dtype=int)
    for L, R in lr:
        a[L-1:R] += 1

    ans = (a == N).sum()
    return ans


def TLE(N, M, lr):
    ans = 0
    for i in range(1, N+1):
        g = 0
        for L, R in lr:
            if L <= i <= R:
                g += 1
        if g == M:
            ans += 1

    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#ABC127C-Prison.py

from sys import stdin

input = stdin.readline

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

L = []
R = []

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

maxL = max(L)
minR = min(R)

if maxL <= N:
    if N >= minR:
        print(minR-maxL+1)
    else:
        print(N-maxL+1)
else:
    print(0)

Submission status: Wrong Answer

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

all_set = None
num_passable = None
for i in range(M):
    L_i, R_i = map(int, input().split())
    L_i_p1 = L_i + 1
    
    if i == 0:
        all_set = set([L_i, R_i, L_i_p1])
    else:
        all_set = all_set & set([L_i, R_i, L_i_p1])
    num_passable = len(all_set)
    if num_passable == 0:
        print(0)
        exit()

print(num_passable)

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 = 1
n_max = 10000000
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(" "))

maxL=0
minR=N

for i in range(M):
    L, R = map(int, input().split(" "))
    maxL=max(maxL, L)
    minR=min(minR, R)


print(minR-maxL+1)

Submission status: Wrong Answer

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

maxl = max(lr[j][0] for j in range(len(lr)))
minr = min(lr[j][1] for j in range(len(lr)))
if n > minr:
    print(minr - maxl +1)
else:
    print(n-maxl +1)

Submission status: Wrong Answer

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

min = -1
max = 1000000
for i in range(m):
    l, r = map(int,input().split())
    if min < l: min = l
    if r < max: max = r

print(max - min + 1)

Submission status: Wrong Answer

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

for i in range(M):
	a, b = map(int, input().split())
	list_s.append(a)
	list_e.append(b)

res = min(list_e) -  max(list_s) + 1
print(res)

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 L > left :
        left = L
    if R < right:
        right = R

print(R-L+1)

Submission status: Wrong Answer

Solution code:
data = [int(s) for s in  input().split()]
l = 0
r = 10000000
flag = 0
for i in range(data[1]):
    gate = [int(s) for s in input().split()]
    
    if l < gate[0]:
        l = gate[0]

    if l > r:
        print(0)
        flag = 1
        

    if r > gate[1]:
        r = gate[1]
    if r < l:
        print(0)
        flga = 1
if flag == 0:
    print(r-l +1)
else:
    pass

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L, R = 1, N
for i in range(M):
	L_i, R_i = map(int, input().split())
	L, R = max(L, L_i), min(R, R_i)

print(R-L+1)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n, m = map(int, input().split())
l, r = 10**6, 0
ll = []
tmp_ans = []
for i in range(m):
    a, b = map(int, input().split())
    atob = list(range(a, b+1, 1))
    ans_l = []
    if i == 0:
        tmp_ans.extend(atob[:])
    else:
        for j in range(len(tmp_ans)):
            if tmp_ans[j] in atob:
                ans_l.append(tmp_ans[j])
        tmp_ans = ans_l[:]
print(len(set(ans_l)))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
lr=[[int(i) for i in input().split()] for i 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:
from sys import stdin

def main():
    N, M = map(int, input().split())
    LR = [tuple(map(int, input().split())) for _ in [0] * M]

    l, r = list(zip(*LR))
    lmax = max(l)
    rmin = min(r)
    ans = 0
    if N >= lmax:
        if N >= rmin:
            ans = rmin - lmax + 1
        else:
            ans = N - lmax + 1
    print(ans)

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

l, r = 0, N
for l_r in L_R:
    if l <= l_r[0]:
        l = l_r[0]
    if l_r[1] <= r:
        r = l_r[1]

print(r - l + 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):
	l,r=[int(i) for i in 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())

Lmax = 1
Rmin = N
for i in range(M):
    L,R = map(int, input().split())
    if Lmax < L:
        Lmax = L
    if R < Rmin:
        Rmin = R
print(Rmin-Lmax+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

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

min_idx = 1
max_idx = 1e+5

for _ in range(M):
    l,r = [int(s) for s in input().split(' ')]
    min_idx = max(min_idx, l)
    max_idx = min(max_idx, r)
if max_idx > min_idx:
    print(int(max_idx - min_idx + 1))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
c=0
o = [1]*n
for i in range(m):
    l, r = map(int, input().split())
    for j in range(n):
        if not(l <= j+1 <= r) and o[j]==1:
            o[j]=0
        elif i==m:
            c+=o[j]
print(c)

Submission status: Wrong Answer

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

l_list = [LR[i][0] for i in range(M)]
r_list = [LR[i][1] for i in range(M)]

l = max(l_list)
r = min(r_list)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())
left=[]
right=[]
for i in range(M):
    A,B=map(int,input().split())
    left.append(A)
    right.append(B)
#print(max(left))
#print(min(right))
if min(right)>N:
    print(N-max(left)+1)
else:
    print(min(right)-max(left)+1)

Submission status: Wrong Answer

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

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

print(min(R_l) - max(L_l) + 1)

Submission status: Wrong Answer

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

arr = [0, n+1]

for i in range(m):
    a , b = map(int, input().split())
    if arr[0] < a:
        arr[0] = a
    if arr[1] > b:
        arr[1] = b

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

Submission status: Wrong Answer

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

x = [0] * M
y = [0] * M
for i in range(M):
    x[i], y[i] = map(int, input().split())
    
print(min(y) - max(x) + 1 )

Submission status: Wrong Answer

Solution code:
#ABC127C-Prison.py

from sys import stdin

input = stdin.readline

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

L = [0]*M
R = [10**5]*M

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

maxL = max(L)
minR = min(R)

if maxL <= N:
    if N >= minR:
        print(minR-maxL+1)
    else:
        print(N-maxL+1)
else:
    print(0)

Submission status: Wrong Answer

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

for i in range(M):
  for j in range(LR[i][1]-LR[i][0]+1):
    elements.append(LR[i][0]+j)

for i in range(max(elements)-1):
  if elements.count(i+1)==M:
    print_num += 1

print(print_num)

Submission status: Wrong Answer

Solution code:
import bisect
N,M = map(int,input().split())
n = list(range(1,N+1))
L_list,M_list = [],[]
for i in range(M):
    l,m = map(int,input().split())
    L_list.append(l)
    M_list.append(m)

L_list.sort()
M_list.sort()
lmax = L_list[-1]
mmin = M_list[0]
min = bisect.bisect_left(n,lmax)
max = bisect.bisect_left(n,mmin)
if min >= max:
    ans = 0
else:
    ans = n[min:max]
    ans = len(ans)+1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def solve(n, m, l, r):
    l_max = max(l)
    r_min = min(r)
    return r_min - l_max + 1


if __name__ == '__main__':

    n, m = map(int, sys.stdin.readline().strip().split(" "))
    l = []
    r = []
    for i in range(m):
        l_tmp, r_tmp = map(int, sys.stdin.readline().strip().split(" "))
        l.append(l_tmp)
        r.append(r_tmp)
    print solve(n, m, l, r)

Submission status: Wrong Answer

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

for i in range(m):
    b,c = map(int, input().split())
    low.append(b)
    high.append(c)
min(high)-max(low)+1

Submission status: Wrong Answer

Solution code:
def main():
    n,m=list(map(int,input().split(' ')))
    l_max=0
    r_min=n
    for i in range(m):
        l,r=list(map(int,input().split(' ')))
        if l>l_max:
            l_max=l
        if r < r_min:
            r_min=r
    print(r_min-l_max+1)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

a_max = -1
b_min = 999999999999999

for i in range(m):
    a, b = map(int, input().split())
    
    a_max = max(a_max, a)
    b_min = min(b_min, b)
    
print(b_min - a_max + 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)

Lmax = 1
Rmin = N
for i in range(M):
    if Lmax < L[i]:
        Lmax = L[i]
    if Rmin > R[i]:
        Rmin = R[i]

num = Rmin - Lmax + 1
print(num)

Submission status: Wrong Answer

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

for i in range(m-1):
    l2,r2 = map(int, input().split())
    if l<l2:
        l=l2
    if r>r2:
        r=r2

print(r-l+1)

Submission status: Wrong Answer

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

l =[]
r =[]
for i in range(m):
    l1, r1 = [int(i) for i in input().split()]
    l.append(l1)
    r.append(r1)

ans = np.zeros(n)
#print(ans)
for i in range(m):
    ans[l[i]-1:r[i]] += 1

#print(ans)
max = np.where(ans == ans.max())
#print(max)
print(len(max[0]))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l=[0]*m
r=[0]*m
for x in range(m):
    l[x],r[x] = map(int,input().split())
lm=max(l)
rm=min(r)
#print(lm)
#print(rm)
print(rm-lm+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)	

print(min(Rs) - max(Ls) + 1)

Submission status: Wrong Answer

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

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

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

ans = ans_max - ans_min + 1

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

Submission status: Wrong Answer

Solution code:
li = input().split()
n = int(li[0])
m = int(li[1])
# IDカードn枚，　ゲートm個
l_r = []
# i番目のゲートはl~rのIDカードを持っていれば通過できる
l_r = [input().split() for i in range(m)]
l_r.sort(key=lambda x:x[0])
l_max = int(l_r[-1][0])
l_r.sort(key=lambda x:x[1])
r_min = int(l_r[0][1])
answer = 0
for i in range(n):
    if l_max <= i + 1 and i + 1 <= r_min:
        answer += 1
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m= input().split()
n = int(n)
m = int(m)
g=[input().split() for i in range(m)]
av =[0,1000000]
for i in range(m):
  av[0] = max(int(g[i][0]),av[0])
  av[1] = min(int(g[i][1]),av[1])
print(av[1] -av[0]+1)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in raw_input ().split()]
X, Y = [int(i) for i in raw_input ().split()]
for i in range(M - 1):
    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())
head, tail = map(int, input().split())
if head >= tail:
    print(0)
    exit()
for i in range(1, M):
    if head >= tail:
        print(0)
        exit()
    x, y = map(int, input().split())
    if x > head:
        head = x
    if y < tail:
        tail = y

print(tail - head + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import math

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

s = 1
t = 10**5
for i in range(m):
    a,b = list(map(int,input().split(" ")))
    if s < a:
        s = a
    if b < t:
        t = b
print(t-s+1)

Submission status: Wrong Answer

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

min_, max_ = map(int, input().split())

for _ in range(M-1):
    LL, MM = map(int, input().split())
    min_ = max(min_, LL)
    max_ = min(max_, MM)

print(max_ - min_ + 1)

Submission status: Wrong Answer

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

N,M=map(int,input().split())
LRs = []
Min=-1
Max=10**5
for _ in range(M):
  L,R=map(int,input().split())
  Min = L if L > Min else Min
  Max = R if Max > R else Max
print(Max-Min+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:
import os, sys, re, math

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

min_idx = 1
max_idx = 1e+5

for _ in range(M):
    l,r = [int(s) for s in input().split(' ')]
    min_idx = max(min_idx, l)
    max_idx = min(max_idx, r)
print(int(max_idx - min_idx + 1))

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
cards = np.array([0] * n)
for i in range(m):
    l, r = map(int, input().split())
    cards[l:r+1] += 1

print(sum(cards == m))

Submission status: Wrong Answer

Solution code:
n,m= input().split()
n = int(n)
m = int(m)
g=[input().split() for i in range(m)]
av =[0,1000000]
for i in range(m):
  av[0] = max(int(g[i][0]),av[0])
  av[1] = min(int(g[i][1]),av[1])
print(av[1])
print(av[0])
print(av[1] -av[0]+1)

Submission status: Wrong Answer

Solution code:
import sys

fin = sys.stdin.readline
N, M = [int(elem) for elem in fin().split()]
conditions = [tuple(int(elem) for elem in fin().split()) for _ in range(M)]

l_list = [x[0] for x in conditions]
r_list = [x[1] for x in conditions]

print(min(r_list) - max(l_list) + 1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())        
                                        
x = []                                  
for i in range(M):                      
    l,r = map(int, input().split())     
    x.append([l, r])                    
                                        
                                        
cand = list(range(1, N+1))              
                                        
for i, p in enumerate(x):               
    l,r = p                             
    if (r < cand[0]) or (l > cand[-1]): 
        continue                        
                                        
    if cand[0] < l:                     
        del cand[:(l - cand[0])]        
    if cand[-1] > r:                    
        del cand[(r-cand[0]+1):]        
                                        
print(len(cand))

Submission status: Wrong Answer

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

answer = 0

for i in range(b):
  c,d=map(int,input().split())
  if b >= c and b <= d:
    answer += 1

print(answer)

Submission status: Wrong Answer

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

min = 0
max = 1000000

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

print(max - min + 1)

Submission status: Wrong Answer

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


def main():
    from itertools import accumulate

    n, m = map(int, input().split())
    imos = [0 for _ in range(n + 1)]

    for i in range(m):
        li, ri = map(int, input().split())
        imos[li - 1] = 1
        imos[ri] = -1

    count = 0

    for i in list(accumulate(imos)):
        if i == m:
            count += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

shita = 1
ue = 100000
for i in range(0, M):
    Li, Ri = map(int, input().split())
    if shita < Li:
        shita = Li
    if Ri < ue:
        ue = Ri

print(max(ue - shita, 0) + 1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
lr =[[int(i)for i in input().split()]for _ in range(M)]
ans =[0,N+1]
for LR in lr:
    if ans[0] < LR[0]:
        ans[0]=LR[0]
    if LR[1] < ans[1]:
        ans[1] =LR[1]
print(ans[1]-ans[0]+1)