n,m=map(int, input().split())
alist=[]
blist=[]
for i in range(m):
  a,b=map(int, input().split())
  alist.append(a)
  blist.append(b)
maxa=max(alist)
minb=min(blist)
if minb>=maxa:
  print(minb-maxa+1)
else:
  print(0) n,m=map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m alist=[] alist [] blist=[] blist [] for i in range(m):
  a,b=map(int, input().split())
  alist.append(a)
  blist.append(b) i range(m) range m a,b=map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b alist.append(a) alist.append alist append a blist.append(b) blist.append blist append b maxa=max(alist) maxa max(alist) max alist minb=min(blist) minb min(blist) min blist if minb>=maxa:
  print(minb-maxa+1)
else:
  print(0) minb>=maxa minb maxa print(minb-maxa+1) print minb-maxa+1 minb-maxa minb maxa 1 print(0) print 0 b=map(int, input().split()) map(int, input().split()) b maxa=max(alist) max(alist) maxa alist=[] [] alist m=map(int, input().split()) map(int, input().split()) m blist=[] [] blist minb=min(blist) min(blist) minb a,b=map(int, input().split()) map(int, input().split()) a n,m=map(int, input().split()) map(int, input().split()) n
n,m=map(int, input().split())
alist=[]
blist=[]
for i in range(m):
  a,b=map(int, input().split())
  alist.append(a)
  blist.append(b)
maxa=max(alist)
minb=min(blist)
if minb>=maxa:
  print(minb-maxa+1)
else:
  print(0)