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-----
4 2
1 3
2 4

-----Sample Output-----
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.

Difficulty: introductory

Starter code:

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

min_i = 1
max_i = n

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

if max_i-min_i>=0:
    print(max_i-min_i+1)
else:
    print(0)

n, m = list(map(int, input().split()))
l, r = 1, n

for i in range(m):
    a, b = list(map(int, input().split()))
    l = max(l, a)
    r = min(r, b)

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


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

L = []

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

res = [L[0][0], L[0][1]]

for i in range(M):
    res = [max(res[0], L[i][0]), min(res[1], L[i][1])]

if res[1] < res[0]:
    print(0)
else: 
    print(res[1] - res[0] + 1)

import math
import collections
import itertools

def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return

def resolve():

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

    print((max(0,Rmin-Lmax+1)))

resolve()


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 min(R) - max(L) >= 0:
  print(min(R) - max(L) + 1)
else:
  print(0)

N,M=map(int,input().split())
 
LR=[list(map(int,input().split())) for _ in range(M)]
 
max_l=0
min_r=10**9
 
for i in range(M):
  if max_l<=LR[i][0]:
    max_l=LR[i][0]
  if min_r>=LR[i][1]:
    min_r=LR[i][1]
print(max(0,min_r-max_l+1))

N, M = map(int, input().split())
L, R = [0]*M, [0]*M
A = set(range(N))
lm, rm = 0, N
for i in range(M):
    L[i], R[i] = map(int, input().split())
    lm = max(lm, L[i])
    rm = min(rm, R[i])
if lm <= rm:
    print(rm-lm+1)
else:
    print(0)

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

INF = float('inf')
ans_l, ans_r = -INF, INF
for l, r in lr:
    ans_l = max(ans_l, l)
    ans_r = min(ans_r, r)
print(max(0, ans_r-ans_l+1))

n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(m)]
f_inf = float("inf")

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

if min_r >= max_l:
    print(min_r - max_l + 1)
else:
    print(0)

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)
if L > R: print(0)
else: print(R - L + 1)

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

card=[0]*(N+2)
ans=[0]*(N+1)
for i in range(M):
	L,R=map(int, input().split())
	card[L]+=1
	card[R+1]-=1
	
cnt=0
for h in range(N+1):
	cnt+=card[h]
	ans[h]=str(cnt)

print(ans.count(str(M)))

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

# 36
n, m = map(int, input().split())
l_max, r_min = -1, float('inf')
for i in range(m):
    li, ri = map(int, input().split())
    l_max = max(l_max, li)
    r_min = min(r_min, ri)

ans = r_min - l_max + 1 if (r_min - l_max >= 0) else 0
print(ans)

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

L = [0] * M
R = [0] * M

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

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

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

l = 0
r = N

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

else:
    print(ans)

import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

N, M = I()
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(0, max_b-min_a+1))

# 先頭の最大と最後尾の最小を求める
card_num, gate_num = map(int, input().split())
lmax, rmin = map(int, input().split()) # 最初の入力がlの最大とrの最小
for i in range(1, gate_num):
    l, r = map(int, input().split())
    lmax = max(lmax, l) # lmaxにlmaxとlの大きい方
    rmin = min(rmin, r) # rminにrminとrの小さい方
print(max(0, rmin-lmax+1)) # 0かrmin-lmax+1の大きい方を出力

N, M = map(int, input().split())
Min = 1
Max = N
for i in range(M):
    L, R = map(int, input().split())
    if Min <= L and R <= Max:
        Min, Max = L, R
    elif Min <= R and R <= Max:
        Max = R
    elif Min <= L and L <= Max:
        Min = L
    elif L <= Min and Max <= R:
        pass
    else:
        Max, Min  = 0, 1
        break
print(Max - Min +1)

N,M = map(int,input().split())
L = [0 for _ in range(N)]
for i in range(M):
  l,r = map(int,input().split())
  l-=1;r-=1 #0index
  L[l] += 1
  if r+1 < N:
    L[r+1] -= 1
S = [0]
for i in range(N):
  temp = L[i] + S[-1]
  S.append(temp)
#print(S)
ans = 0
for i in range(1,N+1):
  if S[i] == M:
    ans += 1
print(ans)

N,M = map(int,input().split())
L = []
R = []
ans = 0
for j in range(M):
  l,r = map(int,input().split())
  L.append(l)
  R.append(r)
Lmax = max(L)
Rmin = min(R)
for i in range(N):
  if Lmax <= i+1 and i+1 <= Rmin:
    ans += 1
print(ans)

# coding: utf-8

def main():
    N, M = list(map(int, input().split()))
    imos = [0] * (N + 2)
    ans = 0

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

    for i in range(1, N + 2):
        imos[i] += imos[i - 1]
        if imos[i] == M and i != N + 1:
            ans += 1
    
    print(ans)

def __starting_point():
    main()

__starting_point()

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

Lm = -1
Rm = float('inf')

for _ in range(M):
    L,R = map(int, input().split())
    Lm = max(L, Lm)
    Rm = min(R, Rm)

print(max(Rm - Lm + 1, 0))

details = list(map(int, input().split()))
N = details[0]
M = details[1]
first = []
second = []
for i in range(M):
    det = list(map(int, input().split()))
    first.append(det[0])
    second.append(det[1])
maxi = max(first)
mini = min(second)
if mini - maxi >= 0:
    print((mini - maxi) + 1)
else:
    print(0)

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


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

minv = gate[0][0]
maxv = gate[0][1]

for x in gate:
  minv = max(minv,x[0])
  maxv = min(maxv,x[1])
  
print((maxv-minv+1 if maxv-minv+1 >= 1 else 0))


n,m = map(int, input().split())
a_max = 1
b_min = n
for i in range(m):
  a,b = map(int, input().split())
  if a > a_max:
    a_max = a
  if b < b_min:
    b_min = b
print(max(0,b_min - a_max + 1))

# import math
# import statistics
# a=input()
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(i)
e1,e2 = list(map(int,input().split()))
#f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
h = []
for i in range(e2):
    h.append(list(map(int,input().split())))
L=[]
R=[]
for i in range(len(h)):
    L.append(h[i][0])
for i in range(len(h)):
    R.append(h[i][1])

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




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)
  
Rm=min(R)
LM=max(L)

if Rm-LM >= 0:
  print(Rm-LM+1)
  
else:
  print(0)

N, M = [int(x) for x in input().split()]
L = list()
R = list()
for i in range(M):
  l, r = [float(x) for x in input().split()]
  L.append(l)
  R.append(r)
Lmax = max(L)
Rmin = min(R)
if(Rmin-Lmax)<0:
  print(0)
else:
  print(int(Rmin-Lmax+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)

# 共通部分を求め、共通部分が無ければ0を出力する
m = max(L)
M = min(R)
if M >= m: print(M-m+1)
else: print(0)

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

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


#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    gates=[]
    n,m = map(int,input().split())
    gates=[list(map(int,input().split())) for _ in range(m)]
    min_data=0
    max_data=10**5+1

    for gate in gates:
        if min_data < gate[0]:
            min_data=min(gate)
        if max_data > gate[1]:
            max_data=max(gate)
    print(len(list(range(min_data,max_data+1))))

def __starting_point():
    main()
__starting_point()

n, m = map(int, input().split())
ok = [0] * (n + 2)
ans = 0
for _ in range(m):
    l, r = map(int, input().split())
    ok[l] += 1
    ok[r + 1] -= 1
for i in range(1, n + 2):
    ok[i] += ok[i - 1]
    if ok[i] == m:
        ans += 1
print(ans)

#import math
#import itertools
import numpy as np
#from collections import deque

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n,m=INTM()
    ls=[]
    rs=[]
    for i in range(m):
        l,r=INTM()
        ls.append(l)
        rs.append(r)
    
    ans=min(rs)-max(ls)+1
    if ans<=0:
        ans=0
    print(ans)



    
def __starting_point():
    do()
__starting_point()

n,m=map(int,input().split())
a=[]
b=[]
for i in range(m):
    l,r=map(int,input().split())
    a.append(l)
    b.append(r)
x=max(a)
y=min(b)

if y-x<0:
    print('0')
else:
    print(y-x+1)

n, m = list(map(int, input().split()))
prel, prer = 0, 1e6
for i in range(m):
    l, r = list(map(int, input().split()))
    prel, prer = max(prel, l), min(prer, r)

if prer >= prel:
    print((prer - prel + 1))
else:
    print((0))


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

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

for i in range(n):
    s[i + 1] += s[i]
print((s.count(m)))


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

a = 1
b = N

for i in range(M):
    if(L[i] >= a and R[i] >= b):
        a = L[i]
    if(L[i] <= a and R[i] <= b):
        b = R[i]
    if(L[i] >= a and R[i] <= b):
        a = L[i]
        b = R[i]
    if(R[i] < a or L[i] > b):
        print(0)
        return


print(b-a+1)

n, m = list(map(int,input().split()))
start = 1
end = n
for i in range(m):
    x, y = list(map(int,input().split()))
    start = max(start, x)
    end = min(end, y)
print((end-start+1 if end-start >=0 else 0))


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(max(1+R-L, 0)) 

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)
if m <= M: print(M-m+1)
else: print(0)

'''
Created on 2020/09/08

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,M=map(int,pin().split())
  L,R=map(int,pin().split())
  for i in range(M-1):
    l,r=map(int,pin().split())
    if L<l and l<=R:
      L=l
    elif R<l:
      print(0)
      return
    if L<=r and r<R:
      R=r
    elif r<L:
      print(0)
      return
  print(R-L+1)
  return 
main()

n,m=list(map(int,input().split()))
l=0
r=99999999
for i in range(m):
  a,b=list(map(int,input().split()))
  l=max(l,a)
  r=min(r,b)
if r>=l:
  print((r-l+1))
else:
  print((0))


import numpy as np

n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
s_np = np.array(s)


if min(s_np[:, 1]) - max(s_np[:, 0]) >= 0:
  print(min(s_np[:, 1]) - max(s_np[:, 0]) + 1)
else:
  print(0)

import sys

n, m = map(int, sys.stdin.readline().split())

l = 1
r = n
for i in range(m):
    new_l, new_r =  map(int, sys.stdin.readline().split())
    if new_l > l:
        l = new_l
    if new_r < r:
        r = new_r
ans = max(0, r - l + 1)
print(ans)

N,M=list(map(int,input().split()))
L,R=list(map(int,input().split()))
for i in range(M-1):
    H,I=list(map(int,input().split()))
    if H>L:
        L=H
    if R>I:
        R=I
    if R<L:
        break
if R<L:
    print((0))
else:
    ans=list(range(L,R+1))
    print((len(ans)))


from itertools import accumulate
N, M = list(map(int, input().split()))

left = 1
right = N

for i in range(M):
    a,b = list(map(int, input().split()))
    left = max(left,a)
    right = min(right, b)

print((max(0,right-left+1)))

# imos = [0] * (N + 2)
# for i in range(M):
#     l, r = map(int, input().split())
#     imos[l] += 1
#     imos[r + 1] -= 1
#
# imos = list(accumulate(imos))
#
# ans = 0
# for im in imos:
#     ans += (im == M)
#
# print(ans)


n,m = map(int,input().split())
lmax, rmin = 0, n

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

print((rmin-lmax)+1 if (rmin-lmax)+1 > 0 else 0)

import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N, M = MI()
    D = [0] * (N+2)
    for i in range(M):
        L, R = MI()
        D[L]+=1
        D[R+1]-=1
    ans = 0
    
    temp = 0
    for i in D[1:]:
        temp+=i
        if temp == M:
            ans+=1
    
    print(ans)
    
    
def __starting_point():
    main()
__starting_point()


details = list(map(int,input().split()))

N = details[0]
M = details[1]


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

smallest_max = ab[0][1]
for i in range(1,M):
    if ab[i][1] < smallest_max:
        smallest_max = ab[i][1]

largest_min = ab[0][0]
for i in range(1,M):
    if ab[i][0] > largest_min:
        largest_min = ab[i][0]



if smallest_max - largest_min >=0:
    print(smallest_max - largest_min + 1)
else:
    print(0)

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

N, M = map(int, input().split())
dp = [0] * (N+1)
for i in range(M):
    l, r = map(int, input().split())
    dp[l-1] += 1
    dp[r] -= 1

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

ans = 0
for i in range(N):
    if dp[i] == M:
        ans += 1

print(ans)

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

ll, rr = 1, l
for l, r in lr:
    if ll <= l <= rr or l <= ll <= r:
        ll, rr = max(ll, l), min(rr, r)
    else:
        print(0)
        return
print(rr-ll+1)

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


n, m = list(map(int, input().split()))
ans = [i for i in range(1, n + 1)]

l_max = 0
r_min = n

for _ in range(m):
    x, y = list(map(int, input().split()))
    l_max = max(l_max, x)
    r_min = min(r_min, y)

print((len([i for i in range(l_max, r_min + 1)])))


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

n,m = list(map(int,input().split()))
min = 1
max = n

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

if min>max:
    print((0))
else:
    print((max-min+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)
ans = min(R) - max(L)+1
print(ans) if ans > 0 else print(0)

# -*- coding: utf-8 -*-
"""
Created on Fri Sep 11 01:27:46 2020

@author: liang
"""

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

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

import numpy as np

n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
s_np = np.array(s)

if min(s_np[:, 1]) - max(s_np[:, 0]) >= 0:
  print(min(s_np[:, 1]) - max(s_np[:, 0]) + 1)
else:
  print(0)

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 if min(b)-max(a) >= 0 else 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())

L_SORT = sorted(L)
R_SORT = sorted(R)

#print(L_SORT)
#print(R_SORT)

L_MAX = L_SORT[M-1]
R_MIN = R_SORT[0]

#print(L_MAX)
#print(R_MIN)


if (R_MIN - L_MAX) < 0:
  print(0)
else:
  print(R_MIN-L_MAX + 1)

import numpy as np
n, m = map(int, input().split())
ans = [0]*n

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

c = list(np.cumsum(ans))
print(c.count(m))

n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]

max_l, min_r = 0, float("inf")
for i in range(m):
  max_l = max(s[i][0], max_l)
  min_r = min(s[i][1], min_r)
  
print(max(min_r - max_l + 1, 0))

def resolve():
    n,m=map(int,input().split())
    l=0
    r=n
    for i in range(m):
        nl,nr=map(int,input().split())
        l=max(l,nl)
        r=min(r,nr)
    print(max(r-l+1,0))
resolve()

n, m = list(map(int, input().split()))
l_list, r_list = [], []

for i in range(m):
	l, r = list(map(int, input().split()))
	l_list.append(l)
	r_list.append(r)

limit_min = max(l_list)
limit_max = min(r_list)
cnt = 0

for i in range(1, n + 1):
	if limit_min <= i <= limit_max:
		cnt += 1

print(cnt)


n,m=map(int,input().split())
mn,mx=-1,10**7
for _ in range(m):
  l,r= map(int,input().split())
  mn=max(mn,l)
  mx=min(mx,r)
ans=max(mx-mn+1,0)
print(ans)

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

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, r = max(L), min(R)
if l > r: print(0)
else: print(r - l + 1)

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

L, R = 0, 10 ** 5 + 1
for _ in range(M):
    l, r = map(int, input().split())
    L = max(L, l)
    R = min(R, r+1)

if R > L:
    result = R - L
else:
    result = 0
print(result)

n,m = map(int, input().split())
left = set()
right = set()
for i in range(m):
  l,r = map(int, input().split())
  left.add(l)
  right.add(r)
mini = max(left)
maxi = min(right)
print(len(range(mini,maxi+1)))

n, m = map(int, input().split())
min_id = 0
max_id = 10**9
for _ in range(m):
    l, r = map(int, input().split())
    min_id = max(l, min_id)
    max_id = min(r, max_id)

ans = max_id - min_id + 1
if ans <= 0:
    print(0)
else:
    print(ans)

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 R < L:
    print(0)
    break
else:
  print(R - L + 1)

import sys
input = sys.stdin.readline
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, r = max(L), min(R)
if l > r: print(0)
else: print(r - l + 1)

n, m = map(int, input().split())
l_r = [ list(map(int, input().split())) for _ in range(m) ]

l_ans = 0
r_ans = float('inf')
for l, r in l_r:
    l_ans = max(l_ans, l)
    r_ans = min(r_ans, r)
if r_ans < l_ans:
    ans = 0
else:
    ans = r_ans-l_ans+1
print(ans) 

n,m=map(int,input().split())
s=0
t=10**10
for i in range(m):
  l,r=map(int,input().split())
  s=max(s,l)
  t=min(t,r)

if s>t:
  print(0)
else:
  print(t-s+1)

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

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

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


N, M = map(int, input().split())
L_lis = []
R_lis = []
for i in range(M):
  L, R = map(int, input().split())
  L_lis.append(L)
  R_lis.append(R)
new_L, new_R = max(L_lis), min(R_lis)
if new_L <= new_R:
  print(new_R - new_L + 1)
else:
  print(0)

n, m = list(map(int, input().split()))
l, r = [], []
for i in range(m):
    a, b = list(map(int, input().split()))
    l.append(a)
    r.append(b)
ans = max(0, min(r)-max(l)+1)
print(ans)


from itertools import accumulate
N, M = list(map(int, input().split()))

# left = 1
# right = N
#
# for i in range(M):
#     a,b = map(int, input().split())
#     left = max(left,a)
#     right = min(right, b)
#
# print(max(0,right-left+1))

imos = [0] * (N + 2)
for i in range(M):
    l, r = list(map(int, input().split()))
    imos[l] += 1
    imos[r + 1] -= 1

imos = list(accumulate(imos))

ans = 0
for im in imos:
    ans += (im == M)

print(ans)


N, M = map(int, input().split())
res = 0
L_max = 0
R_min = 100000
for _ in range(M):
  L, R = map(int, input().split())
  if L_max < L: L_max = L
  if R < R_min: R_min = R
  
  
print(max(0, (R_min - L_max + 1)))

n, m = list(map(int, input().split()))
count = [0] * (n+1)
for i in range(m):
  l, r = list(map(int, input().split()))
  l -= 1
  count[l]+=1
  count[r]-=1
for i in range(n):
  count[i+1] += count[i]
ans = 0
for i in range(n):
  if count[i] == m:
    ans += 1
print(ans)


N,M=map(int,input().split())
mini=0
maxi=N
for _ in range(M):
    mini1,maxi1=map(int,input().split())
    mini=max(mini,mini1)
    maxi=min(maxi,maxi1)
print(max(maxi-mini+1,0))

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


n,m = map(int,input().split())
lower = -float('inf')
upper = float('inf')
for i in range(m):
    l,r = map(int,input().split())
    if l > lower:
        lower = l
    if r < upper:
        upper = r
    if upper < lower:
        upper = 0
        lower = 0
        break
if upper == lower == 0:
    print(0)
else:
    print(upper - lower + 1)

# -*- coding:utf-8 -*-

in_gate = []
out_gate = []
N,M = map(int,input().split())
for _ in range(M):
    temp_l,temp_r = map(int,input().split())
    in_gate.append(temp_l)
    out_gate.append(temp_r)

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

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

L_list = []
R_list = []

for i in range(M):
    A, B = map(int, input().split())
    L_list.append(A)
    R_list.append(B)

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

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(L, max_L)
    min_R = min(R, min_R)

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

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

L,R=[],[]
for i in range(M):
  x,y=map(int,input().split())
  L.append(x)
  R.append(y)
max_l,min_r=max(L),min(R)
print(max(0,min_r-max_l+1))

N,M=list(map(int,input().split()))
diff=[0 for _ in range(N+1)]
for _ in range(M):
    L,R=list(map(int,input().split()))
    diff[L-1]+=1
    diff[R]-=1
ans=0
x=0
for i in range(N):
    x+=diff[i]
    if x==M:
        ans+=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())

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

import numpy as np
n,m=map(int,input().split())
x=[list(map(int,input().split())) for i in range(m)]
print(max(np.min(x,axis=0)[1]-np.max(x,axis=0)[0]+1,0))

n, m, *lr = list(map(int, open(0).read().split()))
print((max(0, min(lr[1::2]) - max(lr[::2]) + 1)))


import sys
import copy
import math
import itertools
import numpy as np
l = [int(c) for c in input().split()]
N=l[0]
M=l[1]
LR=[list(map(int,input().split())) for c in range(M)]
small = 0
large = N
for i in range(M):
    if small<LR[i][0]:
        small=LR[i][0]
    
    if large>LR[i][1]:
        large=LR[i][1]

if  small <= large:
    print(large-small+1)
else:
    print(0)

N,M = map(int,input().split())
lsL = []
lsR = []
for i in range(M):
    L,R = map(int,input().split())
    lsL.append(L)
    lsR.append(R)
print(max(0,min(lsR)-max(lsL)+1))