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:
id, gate=map(int,input().split())
li=[0]*id

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

ans=li.count(max(li))
print(ans)

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]

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

Submission status: Wrong Answer

Solution code:
N, M = [int(x) for x in input().split()]
if M == 1:
    print(N)
elif M == 2:
    print(2)
else:
    print(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)

ml = max(L)
mr = min(R)

print(mr - ml + 1)

Submission status: Wrong Answer

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

print(r-l +1)

Submission status: Wrong Answer

Solution code:
def ando(x, y):
    return (max(x[0], y[0]), min(x[1], y[1]))

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

r = (0, N)
for _ in range(M):
    lr = tuple(map(int, input().split()))
    r = ando(r, lr)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, raw_input().split())
# 文字列の入力
# 出力
card = [[0,0]]*m
for i in range(m):
    card[i]=raw_input().split()

cnt = 0
for i in range(m):
    if m >= int(card[i][0]) and int(card[i][1]) >= m:
        cnt +=1

print cnt

Submission status: Wrong Answer

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

import sys

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

li, ri = [0] * m, [0] * m
for i in range(m):
    li[i], ri[i] = [ int(x) for x in sys.stdin.readline().split() ]
#    
imin=1
imax=n
for i in range(m):
    if li[i]>imin: imin=li[i]
    if ri[i]<imax: imax=ri[i]
#
print( imax-imin+1 )

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

low = 0
high = n
for i in range(0, m):
  tmp = input().split()
  if int(tmp[0]) > low:
    low = int(tmp[0])
  if int(tmp[1]) < high:
    high = int(tmp[1])

print(high-low+1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import accumulate

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

ans = list(accumulate(ans))

count = ans.count(M)

print(count)

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)

ans = rmin - lmax + 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc126_c

N, M = map(int, input().split())
pairs = [[int(c) for c in input().split()] for _ in range(M)]
pairs.sort(key=lambda pair: pair[1])

_, right = pairs[0]
res = -1
for (left, _) in pairs:
    res = max(left, res)

print(right - left + 1)

Submission status: Wrong Answer

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

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())
ans = min(r)-max(l) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
dp = [0 for i in range(n+2)]
for i in range(m):
    a,b = map(int,input().split())
    if a > b:a,b = b,a
    dp[a] = 1
    dp[b+1] = -1
ios = [0 for i in range(n+3)]
for i in range(len(dp)):
    ios[i+1] = ios[i] + dp[i]
ans = 0
for i in range(len(ios)):
    if ios[i] == m:
        ans += 1
print(ans)

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 = map(int, input().split(" "))
min_l = 0
max_l = n
for _ in range(m):
    l, r = map(int, input().split(" "))
    if min_l < l:
        min_l = l
    if r < max_l:
        max_l = r
print(max_l - min_l + 1)

Submission status: Wrong Answer

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

L_li = []
R_li = []

for i in range(M):
    Li, Ri = list(map(int,input().split()))
    L_li.append(Li)
    R_li.append(Ri)

count = 0

for i in range(N):
    if max(L_li) <= N <= min(R_li):
        count += 1

print(str(count))

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())
    if l > ll:
        ll = l
    if r < rr:
        rr = r
print(rr - ll +1)

Submission status: Wrong Answer

Solution code:
from fractions import *
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=map(int,input().split())
a=0
b=n*10**9
for i in range(m):
  x,y=map(int,input().split())
  a=max(a,x)
  b=min(b,y)
ans=b-a+1
print(ans)

Submission status: Wrong Answer

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

lr = [list(map(int, input().split())) for i in range(m)]
left = lr[0][0]
right = lr[0][1]

for i in range(1, m):
    left = max(lr[i][0], left)
    right = min(lr[i][1], right)

print(right - left + 1)

Submission status: Wrong Answer

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

gate_s = sorted(gate,key=lambda x:x[0])
min_r = 1000000
max_l = 0
for i in range(M):
  if gate_s[i][1] < min_r:
    min_r = gate_s[i][1]
    #print(min_r)
  if gate_s[i][0] > max_l:
    max_l = gate_s[i][0]
    #print(max_l)
print(min_r-max_l+1)

Submission status: Wrong Answer

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

lower = 0
upper = n

for i in range(m):
    l, r = map(int, input().split())
    if lower < l:
        lower = l
    if upper > r:
        upper = r

print(upper - lower + 1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


main()

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc127/tasks/abc127_c

NM = [int(i) for i in input().split()]
LR = []
for i in range(NM[1]):
    LR.append([int(i) for i in input().split()])

mi = LR[0][0]
ma = LR[0][1]
for i in range(NM[1]):
    if LR[i][0] > mi:
        mi = LR[i][0]
    if LR[i][1] < ma:
        ma = LR[i][1]
        
print(ma-mi+1)

Submission status: Wrong Answer

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

for i in range(m):
  a,b=map(int,input().split())
  if a>l:
    l=a
  if b<r:
    r=b

print(r-l+1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

l_list = [_lr[0] for _lr in lr]
r_list = [_lr[1] for _lr in lr]

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

Submission status: Wrong Answer

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

min = 0
max = 1000000000
for L, R in LR:
  if(int(L) > min):
    min = int(L)
  if(int(R) < max):
    max = int(R)

print(max-min + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np

n,m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(m)]
n = np.zeros(n,dtype="int16")
for l,r in LR:
  n[l-1:r] += 1
print(sum(n == m))

Submission status: Wrong Answer

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


def main():
    n, m = map(int, input().split())
    lmax = 1
    rmin = 10 ** 5

    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=[]
r=[]
for i in range(m):
    a,b=map(int,input().split())
    l.append(a)
    r.append(b)
    
start=0
end=100001
for i in range(m):
    if start<l[i]:
        start=l[i]
    if end>r[i]:
        end=r[i]
        
print(end-start+1)

Submission status: Wrong Answer

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

LR = [list(map(int, input().split())) for _ in range(M)]
L = [i[0] for i in LR]
R = [i[1] for i in LR]

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
lis=[]
for i in range(m):
    l,r=map(int,input().split())
    for v in range(r-l+1):
        lis.append(r+v)
lis.sort()
ans=0
s=1
li=[]
for k in range(1,len(lis)):
    if lis[k]==lis[k-1]:
        s+=1
    else:
        li.append(s)
        s=1
print(li.count(m))

Submission status: Wrong Answer

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

print(k_max - k_min + 1)

Submission status: Wrong Answer

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

l_max = 1
r_min = n
for l, r in lrs:
    l_max = max(l, l_max)
    r_min = min(r, r_min)

print(r_min - l_max + 1)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
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]

print(ans_max - ans_min + 1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
id_cards = set(i for i in range(N))

l_lim = 1
r_lim = N
for j in range(M):
    li, ri = map(int, input().split())
    if l_lim < li:
        l_lim = li
    if r_lim > ri:
        r_lim = ri
print(r_lim-l_lim + 1)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
LR = [LIST() for _ in range(M)]
lis = [0]*(N+1)

for L, R in LR:
	lis[L] += 1
	lis[R] -= 1

tmp = 0
max_ = 0
range_ = 0
for i in lis:
	tmp += i
	if tmp == M:
		range_ += 1
print(range_+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    li_max = 0
    ri_min = 10 ** 5
    for i in range(M):
        li, ri = map(int, input().split())
        if li > li_max:
            li_max = li
        if ri < ri_min:
            ri_min = ri
    ans = ri_min - li_max + 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

LM=0
RM=1000000

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

	if(L>=LM):
		LM=L

	if(RM>=R):
		RM=R

print(RM-LM+1)

Submission status: Wrong Answer

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

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

if N < M:
    print('0')
elif min(R) >= max(L):
    print(min(R) - max(L) + 1)
else:
    print('0')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

mini,maxim=list(map(int,input().split()))
for _ in range(M-1):
    a,b=list(map(int,input().split()))
    mini=max(a,mini)
    maxim=min(b,maxim)
    
print(min(maxim-mini+1,N))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
mi = None
ma = None
fail = False
for i in range(m):
    l, r = map(int, input().split())
    if mi is None:
        mi = r
    if ma is None:
        ma = l
    ma = max(l, ma)
    mi = min(r, mi)
    if l > ma:
        fail = True
    if r < mi:
        fail = True
if fail:
    print("0")
else:
    print(str(int(mi - ma) + 1))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
# import math
# import random
# import fractions
# import sys
# sys.setrecursionlimit(100000)
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]
N, M = [int(x) for x in stdin.readline().rstrip().split()]

L_max = 0
R_min = N
for i in range(M):
  L, R = [int(x) for x in stdin.readline().rstrip().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:
def solve():
    N, M = [int(_) for _ in raw_input().split()]
    maxL = 0
    minR = N+1
    for i in range(M):
        Li, Ri = [int(_) for _ in raw_input().split()]
        if Li > maxL:
            maxL = Li
        if Ri < minR:
            minR = Ri
    ret = minR - maxL + 1
    print ret

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

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

a = min(l)
b = max(r)

print(b - a + 1)

Submission status: Wrong Answer

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

Ldata = []
Rdata = []
for i in range(m):
	L,R = map(int,input().split())
	Ldata.append(L)
	Rdata.append(R)

Lmax = max(Ldata)
Rmin = min(Rdata)

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

Submission status: Wrong Answer

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

num = [0] * N

L = 1
R = N

for _ in range(M):
    l, r = list(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 = 1
minR = n
for i in range(m):
    l, r = map(int ,input().split())
    maxL = max(l, maxL)
    minR = min(r, minR)
if(maxL < minR):
    print(0)
else:
    print(minR - maxL + 1)

Submission status: Wrong Answer

Solution code:
from fractions import *
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)-min(l))

Submission status: Wrong Answer

Solution code:
import sys

def intinput():
    return map(int,sys.stdin.readline().split())

n,m=intinput()
a1=0
b1=n+1
for i in range(m):
    a,b=intinput()
    a1 = max(a,a1)
    b1 = min(b,b1)
print(b1-a1+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M=list(map(int,input().split()))
s=1
m=N
for i in range(M):
    a,b=list(map(int,input().split()))
    if s<a:
        s=a
    if m>b:
        m=b
    #ans &=tmp
print(m-s+1)

Submission status: Wrong Answer

Solution code:
N,M = (int(i) for i in input().split())
mx,mn = 0,float('inf')
for l,r in [[int(i) for i in input().split()] for i in range(M)]:
    mx = max(l,mx)
    mn = min(r,mn)
print(mn-mx+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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

l_max = 1
r_min = N

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

    l_max = max(l_max, L)
    r_min = min(r_min, R)

print(r_min - l_max + 1)

Submission status: Wrong Answer

Solution code:
n, m = (int(_) for _ in input().split())
currs = 0
currg = 100000000
for i in range(m):
    s, g = (int(_) for _ in input().split())
    if s > currs:
        currs = s
    if g < currg:
        currg = g
print(currg - currs + 1)

Submission status: Wrong Answer

Solution code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#n=int(input())
#li=input().split()
#import fractions
#n=int(input())
#S=input()
#import math

lis=list(map(int,input().split()))
lr=[1,lis[0]]
for i in range(lis[1]):
    lri=list(map(int,input().split()))
    if lr[0]<lri[0]:
        lr[0]=lri[0]
    if lr[1]>lri[1]:
        lr[1]=lri[1]

ans=lr[1]-lr[0]+1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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):
    a, b = map(int, input().split())
    l = max(l, a)
    r = min(r, b)
print(r-l+1)

Submission status: Wrong Answer

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

LR = [list(map(int, input().split())) for _ in range(M)]
L = [i[0] for i in LR]
R = [i[1] for i in LR]

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

Submission status: Wrong Answer

Solution code:
from io import StringIO
from collections import *
from functools import *
import sys


def main(inputs):
    # n = int(next(inputs))
    # n, k = map(int, next(inputs).split())
    # xs = list(map(int, next(inputs).split()))
    n, m = map(int, next(inputs).split())
    xs = [ list(map(int, next(inputs).split())) for _ in range(m) ]
    ls, rs = zip(*xs)
    return min(rs) - max(ls) + 1


def gen_inputs(str_=None):
    inputs = StringIO(str_) if str_ else sys.stdin
    while True:
        a = inputs.readline().rstrip()
        yield a
        pass
    pass


if __name__ == "__main__":
    print(main(gen_inputs()))
    pass

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

n,m=map(int,input().split())
lr=[list(map(int,input().split())) for l in range(m)]
min=1000000
max=0
for i in range(m):
    if lr[i][1]<min:
        min=lr[i][1]
    if lr[i][0]>max:
        max=lr[i][0]
print((min-max)+1)

Submission status: Wrong Answer

Solution code:
def solve2():
    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)
    print(R - L + 1)
solve2()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
dp = [0 for i in range(n+2)]
for i in range(m):
    a,b = map(int,input().split())
    dp[a] = 1
    dp[b+1] = -1
ios = [0 for i in range(n+3)]
for i in range(len(dp)):
    ios[i+1] = ios[i] + dp[i]
ans = 0
for i in range(len(ios)):
    if ios[i] == m:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os


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())
Lmax=max(L)
Rmin=min(R)
print(Rmin-Lmax+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
rl = 1
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())
data=[0]*(N+1)

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

for i  in range(N+1):
    if i==0:
        data[i]=data[i]
    else:
        data[i]+=data[i-1]
print(data.count(M))

Submission status: Wrong Answer

Solution code:
from sys import stdin

N, G = map(int, stdin.readline().split())
dic = {key: 0 for key in range(1, N+1)}
for i in range(G):
  l, r = map(int, stdin.readline().split())
  for j in range(l, r+1):
    dic[j] = -1
  
ans = 0
for key in dic:
  if dic[key] == 0:
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
ans_l = 0
ans_r = n
for i in range(k):
    l,r = map(int,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 = tuple(map(int, input().split()))

L = []
R = []
for i in range(m):
    l, r = tuple(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())
syou,dai = map(int,input().split())
for i in range(m-1):
    l,r = map(int,input().split())
    if syou < l:
        syou = l
    if r < dai:
        dai = r
        
print(dai - syou + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(Rmin - Lmax +1)

Submission status: Wrong Answer

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

L = []
R = []

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

Submission status: Wrong Answer

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

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(l, maxL)
    minR = min(r, minR)
print(minR - maxL + 1)

Submission status: Wrong Answer

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

L=max(l)
R=min(r)

print(R-L+1)

Submission status: Wrong Answer

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

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

if N < M:
    print('0')
else:
    print(min(R) - max(L) + 1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
data = stdin.readline().split()
N, M = int(data[0]), int(data[1])
left = [None] * M
right = [None] * M
for itr in range(M):
    gate = stdin.readline().split()
    left[itr] = int(gate[0])
    right[itr] = int(gate[1])
print(min(right)-max(left) + 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 = [0]*N

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

Submission status: Wrong Answer

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

a=[]
mini,maxim=list(map(int,input().split()))
for _ in range(M-1):
    a,b=list(map(int,input().split()))
    mini=max(a,mini)
    maxim=min(b,maxim)
    
print(maxim-mini+1)

Submission status: Wrong Answer

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

LR = []
max_L = 0
min_R = N
for i in range(M):
    LR = list(map(int, input().split()))
    if max_L < LR[0]:
        max_L = LR[0]
    if min_R > LR[1]:
        min_R = LR[1]

print(min_R-max_L+1)

Submission status: Wrong Answer

Solution code:
def solve(n, m, list1):
    left = 1
    right = n
    for i in range(len(list1)):
        left = max(list1[i][0], left)
        right = min(list1[i][1], right)
    return right-left+1

n, m = map(int, input().split())
list1 = []
for _ in range(m):
    list1 += [list(map(int, input().split()))]
solve(n, m, list1)

Submission status: Wrong Answer

Solution code:
n, m = [int(c) for c in input().split()]
lr = [[int(c) for c in input().split()] for _ in range(m)]
ls, rs = zip(*lr)
print(min(rs) - max(ls) + 1)

Submission status: Wrong Answer

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

a=li[0][0]
b=li[0][1]
for i in range(m-1):
  if li[i+1][0]>a:
    a=li[i+1][0]
  if li[i+1][1]<b:
    b=li[i+1][1]

if b-a+1<n:
  print(b-a+1)
else:
  print(n)

Submission status: Wrong Answer

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

c.reverse()
for i in range(n):
    if c[i] != 0:
        a = i
        break
for i in range(n):
    if d[i] != 0:
        b = i
        break

print(b-n+a+2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l_min=0
r_min=n+1
for i in range(m):
    l_b,r_b=map(int,input().split())
    if l_min<l_b:
        l_min=l_b
    if r_min>r_b:
        r_min=r_b
    #print(l_min,r_min)
print(r_min-l_min+1)

Submission status: Wrong Answer

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

for i in range(M):
    L, R = map(int,input().split())
    if L > minL:
        minL = L

    if R < maxR:
        maxR = R

print(maxR-minL+1)

Submission status: Wrong Answer

Solution code:
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

N, M = rrs()
data = [rrs() for _ in range(M)]

L = data[0][0]
R = data[0][1]

for d in data:
    if L < d[0]:
        L = d[0]
    if R > d[1]:
        R = d[1]

print(max(R - L, 0) + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
G = []
for i in range(M):
    G.append(list(map(int, input().split())))
tG = list(zip(*G))
A = max(tG[0])
B = min(tG[1])

print(B - A + 1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
listC =[]
while True:
    try:
        listC.append(list(map(int,input().split())))
    except:
        break;
N = listC[0][0]
M = listC[0][1]
L = []
R = []
for i in range(1,len(listC)):
    L.append(listC[i][0])
    R.append(listC[i][1])

maxL = max(L)
minR = min(R)
output = minR-maxL+1
print(output)