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

_min = 1
_max = N

for _ in range(M):
    l, r = map(int, input().split(' '))
    _min = max(_min, l)
    _max = min(_max, r)

print(_max - _min + 1)

Submission status: Wrong Answer

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

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

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

print(R-L+1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
import itertools
import heapq
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))


n,m=input_list()
l=0
r=n
for _ in range(m):
    now=input_list()
    l=max(l,now[0])
    r=min(r,now[1])


print(r-l+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def solve(l1, r1, l2, r2):
    if r1 < l2 or r2 < l1:
        return None
    elif l1 < l2 and r1 < r2:
        return [l2, r1]
    elif l1 >= l2 and r1 <= r2:
        return [l1, r1]
    else:
        return [l1, r2]


def main():
    n, m = map(int, input().split())
    ans = [1, n]
    for _ in range(m):
        l, r = map(int, input().split())
        ans = solve(ans[0], ans[1], l, r)
        if ans is None:
            print(0)
            exit(0)
    print(ans[1] - ans[0] + 1)

if __name__ == '__main__':
    main()

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)

L.sort()
R.sort()

if L[-1] > R[0]:
    print("No")
else:
    print(R[0] - L[-1] + 1)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
l=list()
r=list()
for n in range(M):
  L,R=map(int,input().split())
  l.append(L)
  r.append(R)
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())
l=list()
r=list()
for n 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 = list(map(int, input().split()))
high=10**10
low=0
for i in range(m):
    a,b = list(map(int, input().split()))
    if a==b:
        print(1)
        exit()
    if a>low:
        low=a
    if b<high:
        high=b
if low>high:
    print(0)
else:
    print(high-low+1)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int, input().split()))
high=10**10
low=0
for i in range(m):
    a,b = list(map(int, input().split()))
    if a==b:
        print(1)
        exit()
    if a>low:
        low=a
    if b<high:
        high=b
print(high-low+1)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int, input().split()))
high=10**10
low=0
for i in range(m):
    a,b = list(map(int, input().split()))
    if a>low:
        low=a
    if b<high:
        high=b
print(high-low+1)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int, input().split()))
high=10**10
low=0
for i in range(m):
    a,b = list(map(int, input().split()))
    if a>low:
        low=a
    if b<high:
        kigk=b
print(high-low+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l_max = 0
r_min = n+1
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 = map(int, input().split())
gl = []
for i in range(m):
  g = list(map(int, input().split()))
  gl.append(g)
zeroflag = False
for j in range(1, m):
  db = gl[j][0] - gl[j - 1][0]
  da = gl[j][1] - gl[j - 1][1]
  if db >= 0:
    if da >= 0:
      gl[j][1] = gl[j - 1][1]
  else:
    if da >= 0:
      gl[j][0] = gl[j - 1][0]
      gl[j][1] = gl[j - 1][1]
    else:
      gl[j][0] = gl[j - 1][0]
  if gl[j][0] >= gl[j][1]:
    zeroflag = True
    break
if zeroflag == False:
  print(gl[-1][1] - gl[-1][0] + 1)
else:
  print('0')

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
gl = []
for i in range(m):
  g = list(map(int, input().split()))
  gl.append(g)
for j in range(1, m):
  db = gl[j][0] - gl[j - 1][0]
  da = gl[j][1] - gl[j - 1][1]
  if db >= 0:
    if da >= 0:
      gl[j][1] = gl[j - 1][1]
  else:
    if da >= 0:
      gl[j][0] = gl[j - 1][0]
      gl[j][1] = gl[j - 1][1]
    else:
      gl[j][0] = gl[j - 1][0]
print(gl[-1][1] - gl[-1][0] + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
# lr_list = list()
l_list = list()
r_list = list()
for _ in range(m):
    l, r = list(map(int, input().split()))
    l_list.append(l)
    r_list.append(r)
    # lr_list.append(list(map(int, input().split())))

print(min(r_list) - max(l_list) + 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 = [list(i) for i in zip(*LR)]

l = 0
r = N+1

for i in range(M):
    l = max(l, L[i])
    r = min(r, R[i])

print(r-l+1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
N, M = [int(x) for x in stdin.readline().rstrip().split()]
C = np.zeros(N)
Rmin = N
Lmax = 1
for i in range(M):
    L, R = [int(x) for x in stdin.readline().rstrip().split()]
    if R < Rmin:
        Rmin = R
    if L > Lmax:
        Lmax = L
print(N-(Lmax-1)-(N-Rmin))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N, M = map(int, input().split())
    maxL, minR = 0, N+1
    for i in range(M):
        L, R = map(int, input().split())
        maxL = max(L, maxL)
        minR = min(R, minR)
    print(minR - maxL + 1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N, M = map(int, input().split())
    maxL, minR = 0, M+1
    for i in range(M):
        L, R = map(int, input().split())
        maxL = max(L, maxL)
        minR = min(R, minR)
    print(minR - maxL + 1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

left = 1
right = 10**5

for l, r in LR:
    left = max(left, l)
    right = min(right, r)
print(right - left + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(min(S)-max(s)+1)

Submission status: Wrong Answer

Solution code:
def main():
    ini_inp=list(map(lambda x:int(x),input().split()))
    N=ini_inp[0]
    M=ini_inp[1]

    L=[]
    R=[]
    for i in range(M):
        sec_inp=list(map(lambda x:int(x),input().split()))
        L.append(sec_inp[0])
        R.append(sec_inp[1])

    low=L[0]
    up=R[0]
    flag=0
    for i in range(1,M):
        if up>R[i]:
            flag=1
            break
        elif L[i]>=low:
            low=L[i]
        elif R[i]<=up:
            up=R[i]

    if flag==0:
        print(up-low+1)
    else:
        print(0)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
a = []
for i in range(M):
    a.append(list(map(int, input().split())))
b = [0, float("INF")]
for i in range(M):
    b[0] = max(a[i][0], b[0])
    b[1] = min(a[i][1], b[1])
print(b[1] - b[0] + 1)

Submission status: Wrong Answer

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

end = n-1
start = 0

for i in range(m):
    if start <= l[i] and r[i] <= end:
        start = l[i]
        end = r[i]
    elif l[i] < start and r[i] <= end:
        end = r[i]
    elif start <= l[i] and end < r[i]:
        start = l[i]
print(end-start+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
cnt = 0
l_max= 0
r_min = float('inf')
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=map(int,input().split())
cardlist=[]

for i in range(m):
    l,r=map(int,input().split())
    cardlist.append(list(range(l,r+1)))
    #print(cardlist)

if m ==1:
    print(n)
    exit()


else:
    ans=set(cardlist[0]) & set(cardlist[1])
    #print(ans)
    for j in range(2,m):
        ans=ans & set(cardlist[j])
    if m == 2:
        print(len(ans))
        exit()
    #print('ans,set(cardlist[j])',ans,set(cardlist[j]))
print(len(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
def hani(x,min_,max_):
    ret=x
    if x<min_:ret=min_
    if x>max_:ret=max_
    return ret
def seifu(x):
    return x//abs(x)
###################################################
def main():
    N,M=list(map(int,list(input().split())))
    LR=[]
    for a in range(M):
        LR.append(list(map(int,input().split())))
    l=LR[0][0]
    r=LR[0][1]
    for a in range(M):
        l=max(l,LR[a][0])
        r=min(l,LR[a][1])
    d=max(r-l+1,0)
    print(d)


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input("").split(" ")))
permit = [list(map(int, input("").split(" "))) for i in range(M)]
able = [1 for i in range(N)]
l,r = 1, N
for i,j in permit:
  l = max(l, i)
  r = min(r, j)
print(r-l+1)

Submission status: Wrong Answer

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

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

min_a = 1
max_b = N

for i in range(M):
    a,b = [int(i) for i in input().split()]
    if min_a < a:
        min_a = a
    if max_b > b:
        max_b = b

print(max_b-min_a+1)

Submission status: Wrong Answer

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

    l_i,r_i = map(int,input().split())

    l = max(l,l_i)
    r = min (r,r_i)

print(r-l+1)

Submission status: Wrong Answer

Solution code:
def prison(n, m, lrli):

    rmin = 10**5
    lmax = 0

    for i in lrli:
        rmin = min(rmin, i[1])
        lmax = max(lmax, i[0])

    return rmin-lmax+1 if rmin > lmax else 0

def main():
    n, m = map(int, input().split())
    lrli = [list(map(int, input().split()))for i in range(m)]
    print(prison(n, m, lrli))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
lmax=0
rmin=float('inf')
for i in range(m):
    l,r=map(int,input().split())
    lmax=max(lmax,l)
    rmin=min(rmin,r)

print(rmin-lmax+1)

Submission status: Wrong Answer

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


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

for j in range(M):
  for k in range(len(t)):
    if s[j][0]>t[k]:
      t[k]=0
    if s[j][1]<t[k]:
      t[k]=0
t=set(t)
print(len(t)-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
l=1
r=100000
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())
max_L = 1
min_R = N
#print(max_L,min_R)
for i in range(M):
  L,R=map(int, input().split())
  max_L = max([max_L,L])
  min_R = min([min_R,R])
#  print(max_L,min_R)

print(min_R-max_L+1)

Submission status: Wrong Answer

Solution code:
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())
Llist = []
Rlist = []

for i in range(M):
    l, r = map(int, input().split())
    Llist.append(l)
    Rlist.append(r)

print(min(Rlist)-max(Llist)+1)

Submission status: Wrong Answer

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

ll = list()
lr = list()
for i in range (M):
    l, r = map(int, input().split())
    ll.append(l)
    lr.append(r)

print(min(lr) - max(ll) + 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)
  
ans=min(R)-max(L)+1
print(ans)

Submission status: Wrong Answer

Solution code:
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())

lmax=max(l)
rmin=min(r)
if rmin>lmax:
  print(rmin-lmax+1)
else:
  print(0)

Submission status: Wrong Answer

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


l_max = 0
r_min = float('inf')

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

ans = int(r_min-l_max+1)
print(ans)

Submission status: Wrong Answer

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

L = [None] * m
R = [None] * m

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

ans = R[0] - L[m-1] + 1

print(ans)

Submission status: Wrong Answer

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

L = [None] * m
R = [None] * m

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

can = [1]*n

for i in range(m):
    p = set()
    for j in range(m+1):
        t = i+j
        if t < m:
            p.add(L[t])
        else:
            p.add(R[t-m])

    for i in range(n):
        if can[i] == 1:
            if not i+1 in p:
                can[i] = 0

print(can.count(1))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N, M = map(int, input().split())
List = [list(map(int, input().split())) for i in range(M)]

CheckList = [0]*N

for i in range(M):
    L = List[i][0]
    R = List[i][1]
    for j in range(min(L,R)-1,max(L,R)):
        CheckList[j]+=1    
    
    #print(CheckList)
    #重複リスト

print(CheckList.count(max(CheckList)))

#k=0
#while k<N:
#    L = List[k][0]
#    R = List[k][1]

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
hidari=-10**100
migi=10**100
for i in range(m):
  l,r=map(int,input().split())
  if l>migi or r<hidari:
    keep=0
    break
  elif hidari<=l<=r<=migi:
    hidari=l
    migi=r
  elif l<=hidari<=migi<=r:
    pass
  elif l<=hidari<=r<=migi:
    migi=r
  elif hidari<=l<=migi<=r:
    hidari=l
    
res=migi-hidari+1       
print(min(res,n))

Submission status: Wrong Answer

Solution code:
#C
n, m = map(int, input().split())
l = []
r = []
for _ in range(m):
    tmp=list(map(int,input().split()))
    l.append(tmp[0])
    r.append(tmp[1])
lmax = max(l)
rmin = min(r)
print(rmin - lmax + 1)

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(m)]
a = ls[0][0]
b = ls[0][1]
for j in range(1,m):
    a = max(a,ls[j][0])
    b = min(b,ls[j][1])
    print(a)
    print(b)
    if b-a<0:
        print(0)
        sys.exit()
print(b-a+1)

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(m)]
a = ls[0][0]
b = ls[0][1]
for j in range(1,m-1):
    a = max(a,ls[j+1][0])
    b = min(b,ls[j+1][1])
    if b-a<0:
        print(0)
        sys.exit()
print(b-a+1)

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(m)]
a = ls[0][0]
b = ls[0][1]
for j in range(1,m-1):
    a = max(a,ls[j+1][0])
    b = min(b,ls[j+1][1])
    if a-b<0:
        print(0)
        sys.exit()
print(a-b+1)

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(m)]
for j in range(m-1):
    if (max(ls[j]) < min(ls[j+1])) or (min(ls[j]) > max(ls[j+1])):
        print(0)
        sys.exit()
    elif max(ls[j]) >= min(ls[j+1]):
        if min(ls[j]) <= min(ls[j+1]):
            ls[j+1] = [min(ls[j+1]),max(ls[j])]
        else:
            ls[j+1] = [min(ls[j]),max(ls[j])]
    else:
        if min(ls[j]) >= min(ls[j+1]):
            ls[j+1] = [min(ls[j]),max(ls[j+1])]
        else:
            ls[j+1] = [min(ls[j+1]),max(ls[j+1])]
print(ls[m-1][1]-ls[m-1][0]+1)

Submission status: Wrong Answer

Solution code:
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(l,a)
    r = min(r,b)

print(r-l+1)

Submission status: Wrong Answer

Solution code:
def main():
    N, M = list(map(int, input().split(' ')))
    max_l, min_r = 1, N
    for _ in range(M):
        L, R = list(map(int, input().split(' ')))
        max_l = max([max_l, L])
        min_r = min([min_r, R])
    print(min_r - max_l + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
table = np.ones(n, dtype=int)
for i in range(m):
    l, r = map(int, input().split())
    table[:l-1] = 0
    table[r+1:] = 0
print(sum(table))

Submission status: Wrong Answer

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

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

count = 0
minimum = 0
maxmum = 10**9
for i in range(m):
    minimum = max(minimum, lr[i][0])
    maxmum = min(maxmum, lr[i][1])

print(maxmum - minimum + 1)

Submission status: Wrong Answer

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

L = []
R = []

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
ansl = 1
ansr = N
for _ in range(M):
    L, R = map(int, input().split())
    ansl = max(ansl, L)
    ansr = min(ansr, R)
ans = ansr - ansl + 1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(m):
  c,d=map(int,input().split())
  if l<c:
    l=c
  if d<r:
    r=d
    
print(r-l+1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
L,R = map(int,input().split())
pass_card = R - L + 1
for _ in range(M-1):
  L_now,R_now = map(int,input().split())
  if L_now > L:
    pass_card -= (L_now - L)
    L = L_now
  if R_now < R:
    pass_card -= (R - R_now)
    R = R_now
print(pass_card)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
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())

id_range = range(N + 1)

for m in range(M):
  L, R = map(int, input().split())
  if (L not in id_range) and (R not in id_range):
    id_range = range(0)
    break
  if L in id_range:
    id_range = range(L, id_range[len(id_range) - 1] + 1, 1)
  if R in id_range:
    id_range = range(id_range[0], R + 1, 1)
    
id_set = set(id_range)
print(len(set(range(1, N + 1, 1)) & id_set))

Submission status: Wrong Answer

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

def main():
    N, M = map(int, input().split())
    Card = [[] for i in range(M)]
    Diff = [i for i in range(1, N + 1)]

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


main()

Submission status: Wrong Answer

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

id_range = range(N + 1)

for m in range(M):
  L, R = map(int, input().split())
  if L not in id_range and R not in id_range:
    id_range = range(0)
    break
  elif L in id_range:
    id_range = range(L, id_range[len(id_range) - 1] + 1, 1)
    if R in id_range:
      id_range = range(id_range[0], R + 1, 1)
    
id_set = set(id_range)
print(len(set(range(1, N + 1, 1)) & id_set))

Submission status: Wrong Answer

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

id_range = range(N + 1)

for m in range(M):
  L, R = map(int, input().split())
  if L not in id_range and R not in id_range:
    print(0)
    break
  elif L in id_range:
    id_range = range(L, id_range[len(id_range) - 1] + 1, 1)
    if R in id_range:
      id_range = range(id_range[0], R + 1, 1)
    
id_set = set(id_range)
print(len(set(range(1, N + 1, 1)) & id_set))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

for i in range(2,M+1):
    L,R = map(int,input().split())
    
    if (Li<=L and L<=Ri):
        Li = L
        Ri = min(Ri,R)
    elif (R>=Li and R<=Ri):
        Li = max(L,Li)
        Ri = R
    else:
        Li=1
        Ri=0
        break
        
print(Ri-Li+1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

for i in range(2,M+1):
    L,R = map(int,input().split())
    
    if (L<=Ri and R>=Ri):
        Li = L
    elif (R>=Li and Li>=L):
        Ri = R
    elif (R==Ri and L==Li):
        Li=L
        Ri=R
    else:
        Li=1
        Ri=0
        break
        
print(Ri-Li+1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

for i in range(2,M+1):
    L,R = map(int,input().split())
    
    if (L<=Ri and R>=Ri):
        Li = L
    elif (R>=Li and Li>=L):
        Ri = R
    else:
        Li=1
        Ri=0
        break
        
print(Ri-Li+1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

for i in range(2,M+1):
    L,R = map(int,input().split())
    
    if (L<=Ri and R>=Ri):
        Li = L
    elif (R>=Li and Li>=L):
        Ri = R
    else:
        Li=1
        Ri=0
        
print(Ri-Li+1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

for i in range(2,M+1):
    L,R = map(int,input().split())
    
    if (L<=Ri):
        Li = L
    elif (R>=Li):
        Ri = R
    else:
        break #no ID pass can allow entrying all gates

print(Ri-Li+1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

for i in range(2,M+1):
    L,R = map(int,input().split())
    
    if (L<=Ri):
        Li = L
    elif (R>Li):
        Ri = R
    else:
        break #no ID pass can allow entrying all gates

print(Ri-Li+1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

L = 1
R = n

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
L = []
R = []
for i in range(m):
  t1, t2 = map(int, input().split())
  L.append(t1)
  R.append(t2)

maxl = max(L)
minr = min(R)

print(minr-maxl+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n =  R[0] -L[m-1] +1
print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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