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:


S = input()
N = int(S.split(" ")[0])
M = int(S.split(" ")[1])


lArr = []
rArr = []
for i in range(M):
    S = input()
    l1 = int(S.split(" ")[0])
    r1 = int(S.split(" ")[1])
    lArr.append(l1)
    rArr.append(r1)

lArr.sort()
rArr.sort()

l1 = max(lArr)
r1 = min(rArr)

print(r1 - l1 + 1)

Submission status: Wrong Answer

Solution code:
def calculate(l, r, l1, r1):
    l = l1 if l1 >= l else l
    r = r1 if r1 <= r else r
    return l, r


S = input()
N = int(S.split(" ")[0])
M = int(S.split(" ")[1])


arr = [int(item) for item in input().split(" ")]

for i in range(1, M):
    S = input()
    l1 = int(S.split(" ")[0])
    r1 = int(S.split(" ")[1])
    l, r = calculate(arr[0], arr[1], l1, r1)
    arr = [l,r]

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

Submission status: Wrong Answer

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

min_num = 1
max_num = N
for i in range(M):
    min_input, max_input = list(map(int, input().split()))
    if min_input > min_num:
        min_num = min_input
    
    if max_input < max_num:
        max_num = max_input
        
print(max_num- min_num + 1)

Submission status: Wrong Answer

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

L=[]
R=[]

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

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

Submission status: Wrong Answer

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

L=[]
R=[]

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

print(min(R)-max(L)+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=LR[0]
ans=r-l+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]
  ans=r-l+1
print(ans)

Submission status: Wrong Answer

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

for _ in range(M-1):
    l,r = map(int, input().split())
    if R>r:
        R = r
    if L<l:
        L = l

print(R-L+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

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

# (x,y)みたいな構造体をN個まとめてリストにするとき
L = []
R = []
for i in range(M):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L, R = 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 = (int(num) for num in input().split())
x = []
y = []
for i in range(M):
    x1,y1 = (int(num) for num in input().split())
    x.append(x1)
    y.append(y1)
N_zeros = [0] * N

for i in range(M):
    for j in range(x[i]-1 , y[i]-1):
        N_zeros[j] += 1

counter = 0
for i in range(N):
    if N_zeros[i] == M:
        counter += 1
        
print(counter)

Submission status: Wrong Answer

Solution code:
N, M = (int(num) for num in input().split())
x = []
y = []
for i in range(M):
    x1,y1 = (int(num) for num in input().split())
    x.append(x1)
    y.append(y1)
N_zeros = [0] * N

for i in range(M):
    for j in range(x[i] , y[i]):
        N_zeros[j] += 1

counter = 0
for i in range(N):
    if N_zeros[i] == M:
        counter += 1
        
print(counter)

Submission status: Wrong Answer

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

L,R=0,n+1
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())
maxl = 0
minr = 10**5
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:
#ABC-127-C
N, M = map(int, input().split())
L_list  = []
R_list = []
for _ in range(M):
    Li, Ri = map(int, input().split())
    L_list.append(Li)
    R_list.append(Ri)

max_L = max(L_list)
min_R = min(R_list)

if max_L < min_R:
    print(0)
else:
    print(min_R-max_L+1)

Submission status: Wrong Answer

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

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:
import sys
from itertools import accumulate
n, m = [int(i) for i in sys.stdin.readline().split()]
ls = [0 for i in range(n+1)]
for i in range(m):
    l, r = [int(i) for i in sys.stdin.readline().split()]
    l, r = l - 1, r - 1
    ls[l] += 1
    ls[r + 1] -= 1
ls = [i for i in accumulate(ls)]
_max = max(ls)
cnt = 0
for l in ls[:-1]:
    if l == _max:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
n, m = [int(i) for i in sys.stdin.readline().split()]
ls = [0 for i in range(n+1)]
for i in range(m):
    l, r = [int(i) for i in sys.stdin.readline().split()]
    l, r = l - 1, r - 1
    ls[l] += 1
    ls[r + 1] -= 1
ls = [i for i in accumulate(ls)]
_max = max(ls)
cnt = 0
for l in ls:
    if l == _max:
        cnt += 1
print(cnt)

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

ans = 0
for i in range(n):
    if i < l[0]:
        continue
    for j in range(m):
        if not((i + 1) >= l[j] and (i + 1) <= r[j]):
            break
        if j == m - 1:
            ans += 1

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
def solve():
    N, M = map(int, input().split())
    L = [0 for _ in range(M)]
    R = [0 for _ in range(M)]
    for i in range(M):
        L[i], R[i] = map(int, input().split())
    
    ans = R[0] - L[-1] + 1
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

ans = 0
for i in range(n) :
  if l <= i <= r :
    ans += 1
print(ans)

Submission status: Wrong Answer

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

LRs = [list(map(int, input().split())) for i in range(m)]

under = 1
top = 10**5
for i in range(m):
    if LRs[i][0] > under:
        under = LRs[i][0]
    if LRs[i][1] < top:
        top = LRs[i][1]

print(top - under + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
N, M=input().split()
N=int(N)
M=int(M)
i=0
ID_list=[]
ID_sublist=[]
gate_possible_list=[]
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
for i in range(N):
 ID_list.append(i+1)
#print(ID_list)
#for i in range(N)
gate_list =  [list(map(int, input().split(" ")))for i in range(M)]
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！

#x=[]
#y=[]
#t, x, y = [0]*(N+1), [0]*(N+1), [0]*(N+1)#N+1個の空のリストを作成(原点を入れて##るから一つ増える)
#delta_t=0
#delta_x=0
#delta_y=0
#l=0
#t[0],x[0],y[0]=[0, 0, 0]
#とりあえず入力までは完成した．
#for i in range(N):
# t[i+1], x[i+1], y[i+1] = map(int, input().split())
#child_i =  list(map(int, input().split()))
#w_len=len(w)
#w_list=list(w)
#print(len(w_list))
#print(w_list)
#child_il=sorted(child_i)
#print(child_il)#リストの右端のほうが大きい
i=0
j=0
k=0
l=0
m=0
mini=gate_list[0][0]
maxi=gate_list[0][1]
for i in range(M):
  if mini <gate_list[i][0]:
      mini=gate_list[i][0]
i=0
for i in range(M):
  if maxi >gate_list[i][1]:
      maxi=gate_list[i][1]

if maxi-mini<=0:
    print(0)
else:
 print(maxi-mini+1)


      
#for i in range(M):#ゲートの個数分回す
# for j in range(gate_list[i][1]-gate_list[i][0]+1):
#     gate_possible_list.append(gate_list[i][0]+j)
 #print(gate_possible_list)
# for k in range(len(ID_list)):
#     for j in range(len(gate_possible_list)):
#      if ID_list[k]==gate_possible_list[j]:
#         ID_sublist.append(gate_possible_list[j])
#      else:
#          pass
#
# gate_possible_list=[]
# ID_list=[]
# for m in range(len(ID_sublist)):
#  ID_list.append(ID_sublist[m])
# #print(ID_list)
# ID_sublist=[]
#print(len(ID_list))
#これ時間かかりまくり

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(max(0,min(r)-max(l)))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
conditions = [ tuple(map(int,input().split())) for _ in range(m)]
max_l = 0
min_r = float("INF")
for l,r in conditions:
  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())
l=[list(map(int,input().split())) for i in range(m)]
l_max=l[0][0]
r_min=l[0][1]
for i in range(m):
    l_now=l[i][0]
    r_now=l[i][1]
    if l_now>l_max and l_now<=r_min:
        l_max=l_now
    if r_now<r_min and r_now>=l_max:
        r_min=r_now
    
print(r_min-l_max+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

l_max = 1
r_min = N

for l, r in lr:
    l_max = max(l, l_max)
    r_min = min(r, r_min)

print(r_min - l_max + 1)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [fetch_int_input() for _ in range(times)]


N, M = fetch_int_input()
gate_len = fetch_int_inputs(M)
# range_card = [[False] * N for _ in range(M)]
l, r = 0, N
for gl in gate_len:
    if l < gl[0]:
        l = gl[0]
    if r > gl[1]:
        r = gl[1]

# range_card = list(zip(*range_card))
# print(sum([all(r) for r in range_card]))
print(r - l + 1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
l_max = -float("inf")
r_min = float("inf")

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_min>N:
    r_min = N
len(range(l_max, r_min+1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
max_value, min_value = -1, -1
for i in range(m):
  tmp_min_value, tmp_max_value = map(int, input().split())
  min_value = max([min_value, tmp_min_value]) if min_value >= 0 else tmp_min_value
  max_value = min([max_value, tmp_max_value]) if max_value >= 0 else tmp_max_value

# min_value = min_value if min_value <= n else n
# max_value = max_value if max_value <= n else n

print(max_value - min_value + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
max_value, min_value = -1, -1
for i in range(m):
  tmp_min_value, tmp_max_value = map(int, input().split())
  min_value = max([min_value, tmp_min_value]) if min_value >= 0 else tmp_min_value
  max_value = min([max_value, tmp_max_value]) if max_value >= 0 else tmp_max_value

min_value = min_value if min_value <= n else n
max_value = max_value if max_value <= n else n

print(max_value - min_value + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
max_value, min_value = -1, -1
for i in range(m):
  tmp_min_value, tmp_max_value = map(int, input().split())
  min_value = max([min_value, tmp_min_value]) if min_value >= 0 else tmp_min_value
  max_value = min([max_value, tmp_max_value]) if max_value >= 0 else tmp_max_value

min_value = min_value if min_value <= n else n + 1
max_value = max_value if max_value <= n else n + 1

print(max_value - min_value + 1)

Submission status: Wrong Answer

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

lst1 = [i for i in range(1, n + 1)]
# print(lst1)

for i in range(m):
  l, r = map(int, input().split())
  lst = [l + j for j in range(r)]
  lst1 = lst if len(lst1) == 0 else list(set(lst1) & set(lst))
#  print(lst)

print(len(lst1))

Submission status: Wrong Answer

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

lst1 = [i for i in range(1, n + 1)]
print(lst1)

for i in range(m):
  l, r = map(int, input().split())
  lst = [l + j for j in range(r)]
  lst1 = lst if len(lst1) == 0 else list(set(lst1) & set(lst))
  print(lst)

print(len(lst1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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

tmp1 = 0
tmp2 = float('inf')
val = [[] for i in range(M)]
ans = 0
for i in range(M):
    L,R = map(int, input().split())
    val[i].append(L)
    val[i].append(R)
    if R < tmp1:
        print(ans)
        sys.exit()
    if L > tmp1:
        tmp1 = L
    if R < tmp2:
        tmp2 = R
print(tmp2-tmp1+1)

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N,M = MAP()
G = [MAP() for _ in range(M)]

l = 0
r = 10**5+1
for a,b in G:
	if a>l: l=a
	if b<r: r=b

#print(l,r)
print(r-l+1)

Submission status: Wrong Answer

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

a = {i for i in range(1, N+1)}
L_list = []
R_list = []
for i in range(M):
    L, R = map(int, input().split())
    L_list.append(L)
    R_list.append(R)
    # print(a, set([i for i in range(L, R+1)]))
    # a = a & {i for i in range(L, R+1)}
    # print(a, set([i for i in range(L, R+1)]))

print(min(R_list) - max(L_list) + 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+1)
L.sort()
R.sort()
ans=L[-1]-R[0]
print(0 if ans<0 else ans)

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, R = max(L, l), min(R, r)

print(R - L + 1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
mnr = []
mxr = []
for i in range(1,M+1):
  mn , mx = map(int,input().split())
  mnr.append(mn)
  mxr.append(mx)
x = abs(min(mxr)-max(mnr) +1)
print(x)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, M = map(int, input().split())
L, R = 0, 10**6
card = []
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())
lmax=-1
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())
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())
lmax=0
rmin=n

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())
lmax=0
rmin=n

for i in range(m):
  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:
#ABC 127C
import sys
n, m = map(int, sys.stdin.readline().split())

L = 0
R = n
for _ in range(m):
    Li, Ri = map(int, sys.stdin.readline().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())

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 = (int(i) for i in input().split()) 

ans_l = 1
ans_r = n

for i in range(m):
  l, r = (int(i) for i in input().split())
  if l > ans_l:
    ans_l = l
    
  if r < ans_r:
    ans_r = r

print(ans_r - ans_l + 1)

Submission status: Wrong Answer

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

ans_l = 0
ans_r = n

for i in range(m):
  l, r = (int(i) for i in input().split())
  if l > ans_l:
    ans_l = l
    
  if r < ans_r:
    ans_r = r

print(ans_r - ans_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())

min = L[0]
max = R[0]

for j in range(1,M):
    if min < L[j]:
        min = L[j]
    if max > R[j]:
        max = R[j]
print(max-min+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, m = rli()
    bl, br = 1, n
    for i in range(m):
        l, r = rli()
        bl = max(bl, l)
        br = min(br, r)
    print(br-bl+1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M =map(int,input().split())
left = 0
right = 10**5 + 1
for i in range(M):
    l,r = map(int,input().split())
    left = max(l,left)
    right = min(r,right)
print(right - left + 1)

Submission status: Wrong Answer

Solution code:
import heapq

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

left = heapq.nlargest(1, head)[0]
right = heapq.nsmallest(1, tail)[0]
#print(right, left)

print(right-left+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

hidari=0
migi=100000
L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

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

Submission status: Wrong Answer

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

lm=0
rm=float('inf')
for i in range(m):
      lm=max(L[i][0],lm)
      rm=min(L[i][1],rm)
print(rm-lm+1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 0
maxL = 0
minR = INF 
[n,m] = inpl()
for i in range(m):
    [L,R] = inpl()
    maxL = max(maxL,L)
    minR = min(minR,R)

ans = minR - maxL +1





print(ans)

Submission status: Wrong Answer

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

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

for i in range(M-1):
    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
ans = 0
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_max, r_min = 0, 100000000

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

print(r_min-l_max+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
l, r = map(int, input().split())
cards = list(range(l, r+1))

for i in range(1, M):
    l, r = map(int, input().split())
    if r < cards[0] or l > cards[-1]:
        pass
    else:
        cards_new = list(range(l, r+1))
        cards = list(set(cards) & set(cards_new))

print(len(cards))

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M=map(int,input().split(' '))
LR=[list(map(int,input().split(' '))) for i in range(M)]
LR=np.array(LR)

print(min(LR[:,1])-max(LR[:,0])+1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L_answer=0
R_answer=float('inf')
for i in range(M):
  L,R = map(int,input().split())
  L_answer=max(L_answer,L)
  R_answer=min(R_answer,R)
print(R_answer-L_answer+1)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = [int(i) for i in input().split()]
L = [0]*M
R = [0]*M
for i in range(M):
    L[i], R[i] = [int(i) for i in input().split()]
num = np.min(R) - np.max(L) + 1
print(num)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

n, m = map(int, input().split())
card = [0] * (n + 1)

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

ans = 0
for i in accumulate(card):
    if i == m:
        ans += 1
print(ans)

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)]
a = min(lr, key=lambda x: x[0])[0]
b = min(lr, key=lambda x: x[1])[1]
if a <= b:
    print(b-a+1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
lr = [[0] * 2] * m

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

min = 0
max = n

for i in range(m):
    if (min < lr[i][0]):
        min = lr[i][0]

    if (lr[i][1] < max):
        max = lr[i][1]

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

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
lr = [[0] * 2] * m

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

min = 0
max = n

for i in range(m):
    if (min < lr[i][0]):
        min = lr[i][0]

    if (lr[i][1] < max):
        max = lr[i][1]

print(max - min + 1)

Submission status: Wrong Answer

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

sup = []
inf = []
  
for i in range(len(L)):
  sup.append(L[i][1])
  inf.append(L[i][0])
  
sup = min(sup)
inf = max(inf)

if sup - inf <= 0:
  print(0)
else:
  print(sup - inf + 1)

Submission status: Wrong Answer

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

sup = []
inf = []
  
for i in range(len(L)):
  sup.append(L[i][1])
  inf.append(L[i][0])
  
sup = min(sup)
inf = max(inf)

if sup - inf >= 0:
  print(0)
else:
  print(sup - inf + 1)

Submission status: Wrong Answer

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

sup = []
inf = []
  
for i in range(len(L)):
  sup.append(L[i][1])
  inf.append(L[i][0])
  
sup = min(sup)
inf = max(inf)

print(sup - inf + 1)

Submission status: Wrong Answer

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

c_min = -1
c_max = n+1

for i in range(m):
    tmp_min, tmp_max = map(int, input().split())
    if tmp_min > c_min:
        c_min = tmp_min
    if tmp_max < c_max:
        c_max = tmp_max

print(c_max - c_min +1)

Submission status: Wrong Answer

Solution code:
# 2019-11-13 08:30:54(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, m = [int(x) for x in sys.stdin.readline().split()]

    l, r = [], []
    for _ in range(m):
        li, ri = [int(x) for x in sys.stdin.readline().split()]
        l.append(li)
        r.append(ri)
    
    # all_mighty_cards = set(range(1,n+1))
    # for i in range(m):
    #     all_mighty_cards &= set(l[i:] + r[:i+1])

    all_mighty_cards = [l[-1], r[0]]
    for i in range(m-1):
        if l[i] in r[:i+2]:
            all_mighty_cards.append(l[i])


    print(max(all_mighty_cards) - min(all_mighty_cards) + 1)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# 2019-11-13 08:30:54(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, m = [int(x) for x in sys.stdin.readline().split()]

    l, r = [], []
    for i in range(m):
        li, ri = [int(x) for x in sys.stdin.readline().split()]
        l.append(li)
        r.append(ri)
    
    # all_mighty_cards = set(range(1,n+1))
    # for i in range(m):
    #     all_mighty_cards &= set(l[i:] + r[:i+1])
    


    # print(len(all_mighty_cards) if all_mighty_cards else 0)

    print(r[0] - l[-1] + 1 if r[0] >= l[-1] else 0)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# 2019-11-13 08:30:54(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, m = [int(x) for x in sys.stdin.readline().split()]

    l, r = [], []
    for i in range(m):
        li, ri = [int(x) for x in sys.stdin.readline().split()]
        l.append(li)
        r.append(ri)
    
    # all_mighty_cards = set(range(1,n+1))
    # for i in range(m):
    #     all_mighty_cards &= set(l[i:] + r[:i+1])
    


    # print(len(all_mighty_cards) if all_mighty_cards else 0)

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



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# 2019-11-13 08:30:54(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, m = [int(x) for x in sys.stdin.readline().split()]

    l, r = [], []
    for i in range(m):
        li, ri = [int(x) for x in sys.stdin.readline().split()]
        l.append(li)
        r.append(ri)
    
    all_mighty_cards = set(range(1,n+1))
    for i in range(m):
        all_mighty_cards &= set(l[i:] + r[:i+1])
    


    print(len(all_mighty_cards) if all_mighty_cards else 0)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
key = []
for i in range(1,n+1):
    key.append(i)
    
ls = [0,100000]
for i in range(m):
    L,R = map(int,input().split())
    if L > ls[0]:
        ls[0] = L
    if R < ls[1]:
        ls[1] = R
    
    
print(ls[1]-ls[0]+1)