peterverebics/CodeNet_Python_118 huggingface dataset:
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)
n,m = map(int,input().split())
a = []
lmax = 0
rmin = 10**6
for i in range(m):
    a.append(list(map(int,input().split())))
    if a[i][0] > lmax:
        lmax = a[i][0]
    if a[i][1] < rmin:
        rmin = a[i][1]
print(1+rmin-lmax)
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))
N, M = map(int, input().split())

c_min = 1
c_max = 10 ** 5
for i in range(M):
    LM = list(map(int, input().split()))
    c_min = max(c_min, LM[0])
    c_max = min(c_max, LM[1])

print(c_max - c_min + 1)
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)
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)
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)
N, M = [int(a) for a in input().split()]
L = []
R = []

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

mingate = max(L)
maxgate = min(R)
print(maxgate - mingate + 1)
n, m = map(int, input().split())
a = []
for i in range(m):
    a.append(input().split())
haba = a[0]
for i in a:
    if int(haba[0]) < int(i[0]) < int(haba[1]):
        haba[0] = i[0]
    if int(haba[0]) < int(i[1]) < int(haba[1]):
        haba[1] = i[1]
if n < int(haba[0]):
    ans = 0
elif int(haba[0]) <= n <= int(haba[1]):
    ans = n - int(haba[0]) + 1
else:
    ans = int(haba[1]) - int(haba[0]) + 1
print(ans)
n, m = map(int, input().split())

s = [0] * (n+2)

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

ans = [0] * (n+2)
for i in range(1, n+2):
  ans[i] = ans[i-1] + s[i]

print(ans.count(max(ans)))
n, m = map(int, input().split())
max_l = 1
min_r = n 

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

ans = min_r - max_l + 1
print(ans)
n, m = map(int, input().split())

ans_l = 0
ans_r = n
for _ in range(m):
    l, r = map(int, input().split())
    ans_l = max(ans_l, l)
    ans_r = min(ans_r, r)
print(ans_r-ans_l+1)
N,M = map(int, input().split())
l=0
r=N
for _ in range(M):
  ll,rr=map(int,input().split())
  l = max(l,ll)
  r = min(r,rr)
print(rr-ll+1)
N_ID, M_gate = map(int, input().split())
mini = float('inf')
MAX = 0

for i in range(M_gate):
    L, R = map(int, input().split())
    MAX = max(MAX, L)
    mini = min(mini, R)

answer = mini - MAX + 1
print(answer)
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)
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)
n,m = map(int,input().split())
mn = 10**9
mx = -1

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

print(abs(mx-mn)+1)
N,M = map(int,input().split())
LR = [[int(x) for x in input().split()] for _ in range(M)]
L = 1
R = N
for l,r in LR:
  L = max(L,l)
  R = max(R,r)
  
if L > R:
  print(0)
else:
  print(R-L+1)
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)
import numpy as np
N,M = map(int,input().split(" "))
Min = 1
Max = N

for _ in range(M):
    L,R = map(int,input().split(" "))
    if L>Min:
        Min=L
    if R<Max:
        Max=R
print(Max-Min+1)
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)
n,m = map(int,input().split())
gate = [1,n]
for i in range(m):
    l,r = map(int,input().split())
    gate[0] = max(gate[0],l)
    gate[1] = min(gate[1],r)
print(gate[1]-gate[0]+1)
N, M = map(int, raw_input().split())

L = []
R = []

for i in range(M):
    Li, Ri = map(int, raw_input().split())
    L.append(Li)
    R.append(Ri)

ans = min(R) - max(L) + 1

print ans
l = input().split(" ")
n = int(l[0])
m = int(l[1])

r = []
l = []

for i in range(m):
    gatei = input().split(" ")
    li = int(gatei[0])
    ri = int(gatei[1])
    l.append(li)
    r.append(ri)

l.sort()
r.sort()

count = r[0] - l[m-1] + 1
print(count)
N, M = map(int, input().split())
idcard = [[int(j) for j in input().split()] for i in range(M)]
for i in range(1,M):
    idcard[i] = [idcard[i][0], idcard[i-1][1]]
    
print(idcard[M-1][1]-idcard[M-1][0] + 1)
n, m = map(int, input().split())
l = 0
r = float('inf')
for i in range(m):
    li, ri = map(int, input().split())
    lb, rb = True, True
    if l < li and li <= r:
        l = li
    else:
        lb = False
    if r > ri and ri >= l:
        r = ri
    else:
        rb = False
    if not (lb or rb):
        print(0)
        exit()
    # print(l,r)

print(r - l + 1)
n,m = map(int,input().split())
l = list(list(map(int,input().split())) for _ in range (m))
a = l[0][0]
b = l[0][1]
for s,t in l:
  a = max(a,s)
  b = min(b,t)
print(b-a+1)
N,M=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(M)]

ans_left,ans_right=LR[0][0],LR[0][1]
for lr in LR:
    left,right=lr[0],lr[1]
    if ans_left<left:
        ans_left=left
    if ans_right>right:
        ans_right=right
        
if right<left:
    ans=0
else:
    ans=ans_right-ans_left+1
print(ans)
N,M = map(int,input().split())
a = list()
b = list()
for i in range(M):
  tmp_a,tmp_b =  map(int, input().split())
  a.append(tmp_a)
  b.append(tmp_b)
print(min(b)-max(a)+1)
n,m=map(int,input().split())
card =[list(map(int,input().split())) for i in range(m)]
r = card[0][0]
R = card[0][1]
for i in range(m):
    if  r < card[i][0]:
        r = card[i][0]
for i in range(m):
    if card[i][1] < R:
        R = card[i][1]

print(R - r + 1)
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)
if max(L)>min(R):
    print(0)
else:
    print(min(R)-min(L)+1)
N, M = map(int, input().split())


L, R = map(int, input().split())
ar = [i for i in range(L, R+1)]
for i in range(M-1):
      L, R = map(int, input().split())
      if ar[-1] < L or ar[0] > R:
        break
      else:
        if ar[0] < L < ar[-1]:
          ar = [x for x in range(L, ar[-1]+1)]
        elif ar[0] < R <ar[-1]:
          ar = [x for x in range(ar[0], R+1)]
print(len(ar))
def main():
    n, m = map(int, input().split())
    l = [list(map(int, input().split())) for i in range(m)]
    lt = [list(x) for x in zip(*l)]
    if min(lt[1]) - max(lt[0]):
        print(min(lt[1]) - max(lt[0]) + 1)
    else:
        print(0)
if __name__ == '__main__':
    main()
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)
n, m = map(int, input().split())
l = 0
r = float('inf')
for i in range(m):
    li, ri = map(int, input().split())
    lb, rb = True, True
    if l <= li <= r:
        l = li
    elif li < l:
        continue
    else:
        lb = False
    if r >= ri >= l:
        r = ri
    elif ri > r:
        continue
    else:
        rb = False
    if not (lb or rb):
        print(0)
        exit()
    # print(l,r)

print(r - l + 1)
N, M = map(int, input().split())

min, max = map(int, input().split())

for i in range(1, M):
    L, R = map(int, input().split())
    if min < L <= max:
        min = L
    if min <= R < max:
        max = R
print(max-min+1)
N, M = map(int, input().split())
lr = [tuple(map(int, input().split())) for _ in range(M)]

s = [0] * (N + 1)
for i in range(M):
    l, r = lr[i]
    s[l] += 1
    if r + 1 != N + 1:
        s[r + 1] -= 1

ruiseki = [0] * (N + 1)
for i in range(1, N + 1):
    ruiseki[i] += ruiseki[i - 1] + s[i]

max_ = max(ruiseki)
print(ruiseki.count(max_))
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)
n, m = map(int, input().split())
l0, r0 = map(int, input().split())
for j in range(1, m):
    l1, r1 = map(int, input().split())
    l0 = max(l0, l1)
    r0 = min(r0, r1)
print(r0 - l0 + 1)
n, m = map(int, input().split())
cnt = [0] * (n + 3)
cnt_sum = [0] * (n + 1)
for _ in range(m):
    l, r = map(int, input().split())
    cnt[l] += 1
    cnt[r + 1] -= 1
for i in range(1, n + 1):
    cnt_sum[i] = cnt_sum[i - 1] + cnt[i]
print(cnt_sum.count(max(cnt_sum)))
N,M = map(int,input().split())
min = 0
max = N

for _ 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

if min > max:
    print(0)
else:
    print(max - max + 1)
N,M = map(int,input().split())
LR = [list(map(int,input().split())) for i in range(M)]

maxi = 0
mini = 10**6
for lr in LR:
    maxi = max(lr[0],maxi)
    mini = min(lr[1],mini)

print(mini-maxi+1)
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)
N,M=map(int,input().split())
Lmax = 0
Rmin = 1e8
for _ in range(M):
    L,R=map(int,input().split())
    if L > Lmax:
        Lmax = L
    if R < Rmin:
        Rmin = R

print(Rmin - Lmax + 1)
n,m=map(int,input().split())
ll=[list(map(int,input().split())) for i in range(m)]

a=0
b=n
for l,r in ll:
 a=max(a,l)
 b=min(b,r)
print(b-a+1)
N, M = map(int, input().split())
L, R = 1, N
for _ in range(M):
    l, r = map(int, input().split())
    L = max(l, L)
    R = min(r, R)
print(R-L+1)
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)
N,M = map(int, input().split())
LR = list()
for i in range(M):
    LR.append( list(map(int,input().split())) )
L = LR[M-1][0]
R = LR[0][1]
print(R-L+1)
n,m  = map(int,input().split())
lr =[list(map(int,input().split()))for _ in range(m)]

lr.sort(reverse = True)
ansl = lr[0][0]
ansr = 10**9
for i in range(m):
    r = lr[i][1]
    if r >= ansl:
        ansr = min(ansr,r)
ans = ansr-ansl+1
print(ans)
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)
N, M=map(int, input().split())

a=0
b=N
for i in range(M):
  L,R=map(int, input().split())
  a=max(a,L)
  b=min(b,R)
print(b-a+1)
def main():
    n,m=map(int,input().split())
    l=-1
    r=10**5+1
    for _ in range(m):
        l2,r2=map(int,input().split())
        l=max(l,l2)
        r=min(r,r2)
    print(min(r,n)-l+1)
    
if __name__ == "__main__":
    main()
n,m=map(int,input().split())
l,r=1,n
for i in range(m):
    L,R=map(int,input().split())
    l=max(l,L)
    r=min(r,R)
print(r-l+1)
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)
n, m = map(int, input().split())
li = []
ri = []

for i in range(m):
    l, r = map(int, input().split())
    li.append(l)
    ri.append(r)

ans = min(ri)-max(li)+1
print(ans)
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)
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)
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)
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))
N,M = map(int,input().split())

left=1
right=pow(10,5)

for i in range(M):
    L,R=map(int,input().split())
    left=max(left, L)
    right=min(right,R)
ans=right-left+1
print(N if ans>N else ans)
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()
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)
ans = 0
for j in range(1,n+1):
    cnt = 0
    for i in range(m) :
        if l[i] <= j or r[i] == j:
            cnt += 1
            continue
        break
    if cnt == m:
        ans += 1

print(ans)
N,M=map(int,input().split())
G=[list(map(int,input().split())) for _ in range(M)]
mi=0
ma=float("inf")
for i in range(M):
    if G[i][0]>mi:
        mi=G[i][0]
    if G[i][1]<ma:
        ma=G[i][1]
    print(mi,ma)
print(max(ma-mi+1,0))
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)
ans = min_r - max_l + 1
print(ans)
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))
n,m=map(int,input().split())
L,R=10**18,0
for i in range(m):
  l,r=map(int,input().split())
  L=max(L,l)
  R=min(R,r)
if R<L:
  print(0)
else:
  print(R-L+1)
import sys
N,M=map(int,input().split())
_min,_max=map(int,input().split())
for i in range(M-1):
   L,R=map(int,input().split())
   if R<_min or L>_max:
       print(0)
       sys.exit()
   _min,_max=max(_min,L),min(_max,R)
print(_min+1-_max)
N, M = map(int, input().split())
L, R = [], []
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)

m = max(L)
M = min(R)
print(M-m+1)
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)
# 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)
n,m = map(int,input().split())
cards = []
for i in range(m):
    cards.append(list(map(int,input().split())))

min = cards[0][0]
max = cards[0][1]

for i in range(m):
    if cards[i][0] > min:
        min = cards[i][0]
    if cards[i][1] < max:
        max = cards[i][1]

if max >min:
    print(max - min + 1)
else:
    print(0)
N, M, *_LR = map(int, open(0).read().split())
LR = list(zip(*[map(int, iter(_LR))]*2))

L_max = 1
R_min = N

for L,R in LR:
    L_max = max(L, L_max)
    R_min = min(R, R_min)
    
print(R_min - L_max + 1)
N,M = map(int,input().split())
L1 = 0
R1 = N

for m in range(M):
  L2,R2 = map(int,input().split())
  L1 = min(L1,L2)
  R1 = max(R1,R2)
  
print(max(0,R1-L1))
n, m = list(map(int, input().split(' ')))
l = 0
r = 100000
for i in range(m):
    p, q = list(map(int, input().split(' ')))
    l = max(l, p)
    r = min(r, q)
print(r-l + 1)
n,m=map(int,input().split())
ml,mr=map(int,input().split())
for i in range(m-1):
    l,r=map(int,input().split())
    if l>=ml:
        ml=l
    if r<=mr:
        mr=r
print(mr-ml+1)
data=input().split()
N=int(data[0])
M=int(data[1])
data_gate=[input().split() for i in range(M)]
data_min=[]
data_max=[]
for i in range(M):
    data_min.append(int(data_gate[i][0]))
    data_max.append(int(data_gate[i][1]))
m=max(data_min)
M=min(data_max)
ans=M-m+1
print(ans)
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)
n,m = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(m)]

l_max, r_min = 1, 10**5
for di in d:
    l_max = max(l_max, di[0])
    r_min = min(r_min, di[1])
print(r_min - l_max + 1)
n, m = map(int, input().split())
l = [0]*m
r = [0]*m
for i in range(m):
    l[i], r[i] = map(int, input().split())

print(max(min(r) - max(l)+1, n))
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()
n , m = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(m)]

mi = 0
ma = n
for i in range(m):
  mi = max(mi, lr[i][0])
  ma = min(ma, lr[i][1])
  
print(ma-mi+1)
n,m=map(int,input().split())
l_max=0
r_min=10001
for i in range(m):
    l,r=map(int,input().split())
    if l>l_max:
        l_max=l
    if r<r_min:
        r_min=r
print(max(0,r_min-l_max+1))
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)
count=0
for i in range(1,N+1):
  if max(L)<=i<=min(R):
    count+=1
  else:
    break
print(count)
n,m = map(int,input().split())
ans = [i+1 for i in range(n)]
l = []
r = []
for i in range(m):
    l1,r1 = map(int,input().split())
    l.append(l1)
    r.append(r1)
    
left = max(l)
right = min(r)
print(len(ans[left:right+1]))
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)
def main():
    n, m = map(int,input().split()) 
    startlis = []
    endlis = []

    for i in range(m):
        a, b = map(int, input().split())
        startlis.append(a)
        endlis.append(b)
    
    start = max(startlis)
    end = min(endlis)

    print(end - start + 1)





    
if __name__ == "__main__":
    main()
N, M = map(int,input().split())
ID = list(i+1 for i in range(N))
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)
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)
n, m = map(int, input().split())
L = [0] * m
R = [0] * m
judge = [0] * n
for i in range(m):
    L[i], R[i] = map(int, input().split())
    for j in range(L[i], R[i] + 1):
        judge[j - 1] += 1

print(min(R) - max(L) + 1)
N, M = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(M)]

max_l, min_r = 0, N

for l, r in LR:
    max_l = max(l, max_l)
    min_r = min(r, min_r)

print(min_r - max_l + 1)
N,M=map(int, input().split())
l,r=map(int, input().split())
l_max=l
r_min=r
for i in range(M-1):
  l,r=map(int, input().split())
  if l_max<l:
    l_max=l
  if r_min>r:
    r_min=r
print(r_min-l_max+1)
n,m = map(int,input().split())
lists = []
L = []
R = []
for i in range(m):
    l,r = map(int,input().split())
    if m == 1:
        print(r-l+1)
        exit()
    L.append(l)
    R.append(r)
ll = L[0]
rr = R[0]
ans = []
for i in range(m):
    if L[i] <= rr and L[i] >= ll:
        ans.append(L[i])
        ll = L[i]
ans_list = list(range(ll,rr+1))
print(len(ans_list))
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)
n, m = map(int, input().split())
lr = [[int(i) for i in input().split()] for _ in range(m)]
mi, ma = 1, n
for l, r in lr:
    mi, ma = max(mi, l), min(ma, r)
print(ma - mi + 1)
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)
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.sort()
R.sort()

l= L[len(L)-1]
r = R[0]

cnt = r-l+1

print(cnt)
N, M = map(int, input().split())
limL = 1
limR = N
for i in range(M):
  L, R = map(int, input().split())
  limL = max([limL, L])
  limR = min([limR, R])

print(limR-limL+1)
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)
maxl = -10**5-1
minr = 10**5+1
for i in range(m):
  maxl = max(maxl, l[i])
  minr = min(minr, r[i])
print(minr - maxl + 1)
N,M = map(int, input().split())

n = 0
m = 999999

for i in range(M):
  a,b = map(int, input().split())
  n = max(a, n)
  m = min(b , m)

print(m - n + 1)
N,M=map(int,input().split())

l,r=1,N

for _ in range(M):
    L,R=map(int,input().split())
    l=max(L,l)
    r=min(R,r)
    
print(r-l+1)
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)
N, M=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
LR=[[int(i) for i in input().split()] for i in range(M)]  # 二次元配列入力　二次元マップみたいな入力のとき

mi, ma = 0, 10**5

for i in LR:
    mi = max(mi, i[0])
    ma = min(ma, i[1])

print(ma-mi + 1)
n, m = map(int, input().split())
lmax = 0
rmin = 1000
for _ in range(m):
    l, r = map(int, input().split())
    lmax = max(lmax, l)
    rmin = min(rmin, r)
if lmax > rmin:
    print(0)
else:
    print(rmin-lmax+1)
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)
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)
N, M = map(int, input().split())
s = set(range(N))
for i in range(M):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    s = s&set(range(x,y))
print(len(s)+1)
def solve(l,r):
  l_max = max(l)
  r_max = max(r)
  return max(r_max - l_max + 1, 0)
  
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(solve(L,R))
n,m = map(int,input().split())

ans_l = 0
ans_r = 100001

for i in range(m):
    tmp_l,tmp_r = map(int,input().split())
    if ans_l < tmp_l:
        ans_l = tmp_l
    if tmp_r < ans_r:
        ans_r = tmp_r
        
print(ans_r-ans_l+1)
n,m = map(int, input().split())
l = []
r = []
for _ in range(m):
  a,b = map(int, input().split())
  l.append(a)
  r.append(b)
  
print(min(r) - max(l)+1)