n,m=map(int,input().split())
max_ = 0
min_ = n+1
for i in range(m):
  a,b=map(int, input().split())
  max_ = max(max_, a)
  min_ = min(min_, b)
#print(max_, min_)
if(min_ < max_):print(0)
else:print(min_-max_+1) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m max_ = 0 max_ 0 min_ = n+1 min_ n+1 n 1 for i in range(m):
  a,b=map(int, input().split())
  max_ = max(max_, a)
  min_ = min(min_, b)
#print(max_, min_) i range(m) range m a,b=map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b max_ = max(max_, a) max_ max(max_, a) max max_ a min_ = min(min_, b) min_ min(min_, b) min min_ b if(min_ < max_):print(0)
else:print(min_-max_+1) min_ < max_ min_ max_ a,b=map(int, input().split()) map(int, input().split()) a b=map(int, input().split()) map(int, input().split()) b max_ = max(max_, a) max(max_, a) max_ m=map(int,input().split()) map(int,input().split()) m n,m=map(int,input().split()) map(int,input().split()) n max_ = 0 0 max_ min_ = n+1 n+1 min_ min_ = min(min_, b) min(min_, b) min_
n,m=map(int,input().split())
max_ = 0
min_ = n+1
for i in range(m):
  a,b=map(int, input().split())
  max_ = max(max_, a)
  min_ = min(min_, b)
#print(max_, min_)
if(min_ < max_):print(0)
else:print(min_-max_+1)