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

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

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