n,m,*a=map(int,open(0).read().split())
b=min(a[1::2])-max(a[::2])+1
print(b if b>0 else 0) n,m,*a=map(int,open(0).read().split()) n map(int,open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split m *a a b=min(a[1::2])-max(a[::2])+1 b min(a[1::2])-max(a[::2])+1 min(a[1::2])-max(a[::2]) min(a[1::2]) min a[1::2] a 1::2 1 2 max(a[::2]) max a[::2] a ::2 2 1 print(b if b>0 else 0) print b if b>0 else 0 b>0 b 0 b 0 n,m,*a=map(int,open(0).read().split()) map(int,open(0).read().split()) n b=min(a[1::2])-max(a[::2])+1 min(a[1::2])-max(a[::2])+1 b m,*a=map(int,open(0).read().split()) map(int,open(0).read().split()) m
n,m,*a=map(int,open(0).read().split())
b=min(a[1::2])-max(a[::2])+1
print(b if b>0 else 0)