a = input().split()
N = int(a[1])
mini = []
maxi = []

for i in range(N):
  b = input().split()
  mini.append(b[0])
  maxi.append(b[1])
  
c = [int(s) for s in mini]
d = [int(s) for s in maxi]

c = sorted(c)
d = sorted(d, reverse=True)
e = min(d) - max(c)

if e >= 0:
  print(e + 1)
else:
  print(0) a = input().split() a input().split() ().split () input split N = int(a[1]) N int(a[1]) int a[1] a 1 mini = [] mini [] maxi = [] maxi [] for i in range(N):
  b = input().split()
  mini.append(b[0])
  maxi.append(b[1])
   i range(N) range N b = input().split() b input().split() ().split () input split mini.append(b[0]) mini.append mini append b[0] b 0 maxi.append(b[1]) maxi.append maxi append b[1] b 1 int(s) for s in mini for s in mini s mini for s in mini int(s) int s c = [int(s) for s in mini] c [int(s) for s in mini] int(s) for s in maxi for s in maxi s maxi for s in maxi int(s) int s d = [int(s) for s in maxi] d [int(s) for s in maxi] c = sorted(c) c sorted(c) sorted c d = sorted(d, reverse=True) d sorted(d, reverse=True) sorted d reverse=True reverse True e = min(d) - max(c) e min(d) - max(c) min(d) min d max(c) max c if e >= 0:
  print(e + 1)
else:
  print(0) e >= 0 e 0 print(e + 1) print e + 1 e 1 print(0) print 0 N = int(a[1]) int(a[1]) N e = min(d) - max(c) min(d) - max(c) e c = sorted(c) sorted(c) c maxi = [] [] maxi d = [int(s) for s in maxi] [int(s) for s in maxi] d d = sorted(d, reverse=True) sorted(d, reverse=True) d a = input().split() input().split() a c = [int(s) for s in mini] [int(s) for s in mini] c b = input().split() input().split() b mini = [] [] mini
a = input().split()
N = int(a[1])
mini = []
maxi = []

for i in range(N):
  b = input().split()
  mini.append(b[0])
  maxi.append(b[1])
  
c = [int(s) for s in mini]
d = [int(s) for s in maxi]

c = sorted(c)
d = sorted(d, reverse=True)
e = min(d) - max(c)

if e >= 0:
  print(e + 1)
else:
  print(0)