n,m=[int(x) for x in input().split()]
L=0
R=1000000
for i in range(m):
  l,r=[int(x) for x in input().split()]
  L=max(L,l)
  R=min(R,r)
ans=R-L+1
if ans<=0:
  print(0)
else:
  print(ans) int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x n,m=[int(x) for x in input().split()] n [int(x) for x in input().split()] m L=0 L 0 R=1000000 R 1000000 for i in range(m):
  l,r=[int(x) for x in input().split()]
  L=max(L,l)
  R=min(R,r) i range(m) range m int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x l,r=[int(x) for x in input().split()] l [int(x) for x in input().split()] r L=max(L,l) L max(L,l) max L l R=min(R,r) R min(R,r) min R r ans=R-L+1 ans R-L+1 R-L R L 1 if ans<=0:
  print(0)
else:
  print(ans) ans<=0 ans 0 print(0) print 0 print(ans) print ans n,m=[int(x) for x in input().split()] [int(x) for x in input().split()] n l,r=[int(x) for x in input().split()] [int(x) for x in input().split()] l R=min(R,r) min(R,r) R L=max(L,l) max(L,l) L m=[int(x) for x in input().split()] [int(x) for x in input().split()] m R=1000000 1000000 R ans=R-L+1 R-L+1 ans r=[int(x) for x in input().split()] [int(x) for x in input().split()] r L=0 0 L
n,m=[int(x) for x in input().split()]
L=0
R=1000000
for i in range(m):
  l,r=[int(x) for x in input().split()]
  L=max(L,l)
  R=min(R,r)
ans=R-L+1
if ans<=0:
  print(0)
else:
  print(ans)