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