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())
LR = [list(map(int, input().split())) for i in range(M)]

ListL = []
ListR = []

for i in range(M):
    ListL.append(LR[i][0])

for i in range(M):
    ListR.append(LR[i][1])

print(min(ListR)-max(ListL)+1)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n, m = map(int, input().split())
minv = 1
maxv = n
for _ in range(m):
    l, r = map(int, input().split())
    if maxv > r: maxv = r
    if minv < l: minv = l
print(maxv - minv + 1)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,m=map(int, input().split())
    l=[list(map(int, input().split())) for i in range(m)]
    a=10**5
    b=0
    for i in range(m):
        a=min(a,l[i][1])
    for i in range(m):
        b=max(b,l[i][0])
    print(a-b+1)
resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(max-min+1)

Submission status: Wrong Answer

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

print(max-min+1)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
L = 0
R = float('inf')

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

print(R-L+1)

Submission status: Wrong Answer

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

ans = [a[0],b[0]]

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

if (ans[1]-ans[0] +1)<= 0:
    print(0)
    exit()

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

Submission status: Wrong Answer

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

ans = [a[0],b[0]]

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

if (ans[1]-ans[0] +1)< 0:
    print(0)
    exit()

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

Submission status: Wrong Answer

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

ans = [a[0],b[0]]

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

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

Submission status: Wrong Answer

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

l = 0
r = n-1

for l1,r1 in lr:
    l = max(l, l1)
    r = min(r, r1)

print(max(0, r - l + 1))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]
max_l,min_r=0,10**9

for i in li:
    max_l = max(max_l,i[0])
    min_r = min(min_r,i[1])
if min_r > max_l:
    print(min_r-max_l+1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]
max_l,min_r=0,10**9

for i in li:
    max_l = max(max_l,i[0])
    min_r = min(min_r,i[1])
print(min_r-max_l+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]
max_l,min_r=0,10**9

for i in range(len(li)-1):
    max_l = max(li[i][0],li[i+1][0])
    min_r = min(li[i][1],li[i+1][1])
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())
    L = max(L, l)
    R = min(R, r)

print(R - L + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def two_input():
    return map(int, input().split())

N, M = two_input()
LR = [list(two_input()) for i in range(M)]

cnt = 0
for i in range(1, N+1):
    cnt += 1
    for j in range(M):
        if LR[j][0] > i or LR[j][0]+j+1 < i  and i != LR[j][1]:
            cnt -= 1
            break

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n,k=map(int,input().split())
L=[0]*(n+1)
und=0
top=10**5
for i in range(k):
    a,b=map(int,input().split())
    und=max(und,a)
    top=min(b,top)
print(top-und+1 if top>und else 0)

Submission status: Wrong Answer

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

n,k=map(int,input().split())
L=[0]*(n+1)
und=0
top=10**5
for i in range(k):
    a,b=map(int,input().split())
    und=max(und,a)
    top=min(b,top)
print(top-und+1)

Submission status: Wrong Answer

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

n,k=map(int,input().split())
L=[0]*(n+1)
for i in range(k):
    a,b=map(int,input().split())
    for j in range(a,b+1):
        L[j]+=1
print(L.count(max(L)))

Submission status: Wrong Answer

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

for i in range(m):
    l,r = map(int,input().split())
    card.append(l)
    card.append(r)
    card = sorted(card)
    card = card[1:3]
    
print(card[1]-card[0]+1)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
#b = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y = list(map(int, input().split()))
    l.append(x)
    r.append(y)
L = l[0]
R = r[0]
for i in range(1, m):
    if not((R < l[i] and R < r[i]) or (r[i] < L and l[i] < L)):
        L = max(L, l[i])
        R = min(R, r[i])

print(R-L+1)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
#b = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y = list(map(int, input().split()))
    l.append(x)
    r.append(y)
L = l[0]
R = r[0]
for i in range(1, m):
    L = max(L, l[i])
    R = min(R, r[i])

print(R-L+1)

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
#b = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y = list(map(int, input().split()))
    l.append(x)
    r.append(y)
nowL = l[0]
nowR = r[0]
L = 1
R = n
for i in range(1, m):
    L = max(nowL, l[i])
    R = min(nowR, r[i])
    nowL = L
    nowR = R

print(R-L+1)

Submission status: Wrong Answer

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def solve():
    n, m = MI()

    maxl, minr = MI()
    for _ in range(m-1):
        l, r = MI()
        if maxl < l:
            maxl = min(l, minr)
        if r < minr:
            minr = max(maxl, r)
    print(minr - maxl + 1)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def solve():
    n, m = MI()

    maxl, minr = MI()
    for _ in range(m-1):
        l, r = MI()
        if maxl < l:
            maxl = l
        if r < minr:
            minr = r
    print(minr - maxl + 1)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

left=0
right=10**6

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

print(right-left+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = [int(x) for x in input().split()]

l_list = [0] * m
r_list = [0] * m
for i in range(m):
    l_list[i], r_list[i] = [int(x) for x in input().split()]

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

Submission status: Wrong Answer

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

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, m = mi()
    l_list = []
    r_list = []
    for _ in range(m):
        l, r = mi()
        l_list.append(l)
        r_list.append(r)
    print(min(r_list)-max(l_list)+1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

left = 0
right = N

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

print(right - left + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
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)
Lmax = max(L)
Rmax = min(R)
print(Rmax-Lmax+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
p=1
q=n
for i in range(m):
  l,r=map(int,input().split())
  if p<l:
    p=l
  if r<q:
    q=r
  if p>q:
    print(0)
    break
print(q-p+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)
a = max(l)
b = min(r)
print(b - a + 1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import itertools


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


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
l_list = []
r_list = []
for i in range(M):
    l, r = lr()
    l_list.append(l)
    r_list.append(r)

for i in range(M):
    if i == 0:
        maxL = l_list[i]
        minR = r_list[i]
        continue
    maxL = max(maxL, l_list[i])
    minR = min(minR, r_list[i])
ans = max(minR - maxL + 1, 0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import itertools


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


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
l_list = []
r_list = []
for i in range(M):
    l, r = lr()
    l_list.append(l)
    r_list.append(r)

maxL = 0
minR = 100000000
for i in range(M):
    if maxL == 0:
        maxL = l_list[i]
        minR = r_list[i]
        continue
    maxL = max(maxL, l_list[i])
    minR = min(minR, r_list[i])
ans = max(minR - maxL + 1, 0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import itertools


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


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
l_list = []
r_list = []
for i in range(M):
    l, r = lr()
    l_list.append(l)
    r_list.append(r)

maxL = 0
minR = 100000000
for i in range(M):
    if maxL == 0:
        maxL = l_list[i]
        minR = r_list[i]
        continue
    max(maxL, l_list[i])
    min(minR, r_list[i])
ans = max(minR - maxL + 1, 0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import itertools


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


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
l_list = []
r_list = []
for i in range(M):
    l, r = lr()
    l_list.append(l)
    r_list.append(r)

maxL = 0
minR = 100000000
for i in range(M):
    if maxL == 0:
        maxL = l_list[i]
        minR = r_list[i]
        continue
    max(maxL, l_list[i])
    min(minR, r_list[i])
ans = max(maxL - minR + 1, 0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import itertools


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


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
l_list = []
r_list = []
for i in range(M):
    l, r = lr()
    l_list.append(l)
    r_list.append(r)

maxL = 0
minL = 0
for i in range(M):
    if maxL == 0:
        maxL = l_list[i]
        minR = r_list[i]
        continue
    max(maxL, l_list[i])
    min(minR, r_list[i])
ans = max(maxL - minR + 1, 0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import itertools


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


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
l_list = []
r_list = []
for i in range(M):
    l, r = lr()
    l_list.append(l)
    r_list.append(r)

# ans = set()
# left = l_list[M - 1]
# right = r_list[0]
tl_list = []
tr_list = []
for i in range(M):
    tmp_left = l_list[i]
    tmp_right = r_list[i]
    tl_list.append(tmp_left)
    tr_list.append(tmp_right)
left = max(tl_list)
right = min(tr_list)
# cards = sorted(l_list[i:] + r_list[:i + 1])
# cards = set(range(cards[0], cards[-1] + 1, 1))
# if (len(ans) == 0):
#     ans = cards
#     continue

# ans = cards & ans

print(right - left + 1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import itertools


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


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
l_list = []
r_list = []
for i in range(M):
    l, r = lr()
    l_list.append(l)
    r_list.append(r)

ans = set()
left = l_list[M - 1]
right = r_list[0]
# for i in range(M):
# left = l_list[i]
# right = r_list[i + 1]
# cards = sorted(l_list[i:] + r_list[:i + 1])
# cards = set(range(cards[0], cards[-1] + 1, 1))
# if (len(ans) == 0):
#     ans = cards
#     continue

# ans = cards & ans

print(right - left + 1)

Submission status: Wrong Answer

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

l,r=m[0][0],m[0][1]

for i in range(1,a):
    l = max(m[i][0],l)
    r = min(m[i][1],r)

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)

max_l = max(L)
min_r = min(R)
print(min_r - max_l + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
L, R = 0, float('inf')
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())
#v = list(map(int,input().split()))

#a = [0 for _ in range(n+1)]
ml = -1
mr = 10**6
for i in range(m):
  l,r = map(int,input().split())
  ml = max(ml,l)
  mr = min(mr,r)

res = mr-ml + 1
print(res)

Submission status: Wrong Answer

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

#a = [0 for _ in range(n+1)]
ml = -1
mr = 10**6
for i in range(m):
  l,r = map(int,input().split())
  ml = max(ml,l)
  mr = min(mr,r)
  
res = ml - mr + 1
print(res)

Submission status: Wrong Answer

Solution code:
import sys
N, M = map(int, sys.stdin.readline().split())
LR = sorted([list(map(int,sys.stdin.readline().split())) for i in range(M)])
if LR[0][1] - LR[M-1][0] >= 0:
    print(LR[0][1] - LR[M-1][0] + 1)
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
LR=[]
for i in range(M):
  LR.append(list(map(int,input().split())))
l,r=LR[0][0],LR[0][1]
for i in range(M):
  if LR[i][0]<l and LR[i][1]<r:
    r=LR[i][1]
  elif l<LR[i][0] and LR[i][1]<r:
    l,r=LR[i][0],LR[i][1]
  elif l<LR[i][0] and r<LR[i][1]:
    l=LR[i][0]
print(r-l+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
card = [0]*n
def calc(n):
    return n + 1

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

print(card.count(max(card)))

Submission status: Wrong Answer

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

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

print(card.count(max(card)))

Submission status: Wrong Answer

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

ml = 0
mm = 10**7
for v in L:
    ml = max(ml, v[0])
    mm = min(mm, v[1])

print(mm - ml + 1)

Submission status: Wrong Answer

Solution code:
# C - Prison

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

ansl = 1
ansr = n

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

print(ansr-ansl+1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    Lmax  = 0
    Rmin  = N+1
    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)
main()

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
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N, M = MAP()

LR = [LIST() for _ in range(M)]
LR = np.transpose(LR)

print(min(LR[1]) - max(LR[0]) + 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())
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]*m
r=[0]*m
for i in range(m):
    l[i],r[i]=map(int,input().split())
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]*m
r=[0]*m
for i in range(m):
    l[i],r[i]=map(int,input().split())
if max(l)<min(r):
    print(0)
elif 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())
min = -1
max = 10**5+1
for i in range(M):
    L, R = map(int, input().split())
    if L > min:
        min = L
    if R < max:
        max = R

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

Submission status: Wrong Answer

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

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

for i in rc:
    tmp = tmp & set(range(i[0],i[1]))

print(len(tmp))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

min1=1
max1=N

for j in gate:
  if j[0]>min1:
    min1=j[0]
  if j[1]<max1:
    max1=j[1]
print(max1-min1+1)

Submission status: Wrong Answer

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

min1=0
max1=1000000000

for j in gate:
  if j[0]>min1:
    min1=j[0]
  if j[1]<max1:
    max1=j[1]
print(max1-min1+1)

Submission status: Wrong Answer

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

start=1
end=n
for line in input_lines:
    if line[0]>start:
        start=line[0]
    if line[1]<end:
        end=line[1]
print(end-start+1)

Submission status: Wrong Answer

Solution code:
import sys
N,M=map(int, sys.stdin.readline().split())
ll=float("-inf")
rr=float("inf")
for _ in range(M):
    l,r=map(int, sys.stdin.readline().split())
    ll=max(ll,l)
    rr=min(rr,r)

print rr-ll+1

Submission status: Wrong Answer

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

for i in range(m-1):
    l,r=map(int,input().split())
    if r<L:
        L,R=0,0
        break
    if R<l:
        L,R=0,0
        break
    L=max(L,l)
    R=min(R,r)
print(R-L+1)

Submission status: Wrong Answer

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

ma = 0
mi = float("INF")
for i in range(0,m):
    ma = max(ma,A[i][0])
    mi = min(mi,A[i][1])

ans = mi-ma+1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

left = 0
right = n

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

print(right - left + 1)

Submission status: Wrong Answer

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

for i in range(m):
    s = list(map(int, input().split()))
    l_i = s[0]
    r_i = s[1]
    card_id += s
    
    if i == 0:
        open_id = set((range(l_i, r_i + 1)))
    else:
        open_id = set(open_id) & set((range(l_i, r_i + 1)))
    
ans_set = open_id & set(card_id)
print(len(ans_set))

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
lr = [map(int, input().split()) for _ in range(m)]
l, r = [list(i) for i in zip(*lr)]
answer = (max(r)  - min(l)  +1) 
if answer > 0:
    print(answer)
else:
    print("0")

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
lr = [map(int, input().split()) for _ in range(m)]
l, r = [list(i) for i in zip(*lr)]
answer = (max(l)  - min(r)  +1) 
if answer > 0:
    print(answer)
else:
    print("0")

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
lr = [map(int, input().split()) for _ in range(m)]
l, r = [list(i) for i in zip(*lr)]
answer = (r[0]  - l[-1]  +1) 
if answer > 0:
    print(answer)
else:
    print("0")

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
lr = [map(int, input().split()) for _ in range(m)]
l, r = [list(i) for i in zip(*lr)]
answer = (r[0]  - l[-1]  +1) 
if answer > 1:
    print(answer)
else:
    print("0")

Submission status: Wrong Answer

Solution code:
n,m=map(int, input().split())
lr = [map(int, input().split()) for _ in range(m)]
l, r = [list(i) for i in zip(*lr)]
answer = (r[0]  - l[-1]  +1) 
print(answer)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
b=min(ab[i][1] for i in range(m))
a=max(ab[i][0] for i in range(m))
print(b-a+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

l = []
r = []

for i in range(m):
  l.append(a[i][0])
  r.append(a[i][1])
    

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

Submission status: Wrong Answer

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

if __name__ == "__main__":
    main()