n,m = map(int, input().split())
x = [0]*n
a = 0
l  =[0]*m
r = [0]*m
for i in range(m):
  l[i],r[i]=map(int,input().split())
a = min(r)-max(l)+1
print(max(0,a)) n,m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m x = [0]*n x [0]*n [0] 0 n a = 0 a 0 l  =[0]*m l [0]*m [0] 0 m r = [0]*m r [0]*m [0] 0 m for i in range(m):
  l[i],r[i]=map(int,input().split()) i range(m) range m l[i],r[i]=map(int,input().split()) l[i] l i map(int,input().split()) map int input().split() ().split () input split r[i] r i a = min(r)-max(l)+1 a min(r)-max(l)+1 min(r)-max(l) min(r) min r max(l) max l 1 print(max(0,a)) print max(0,a) max 0 a m = map(int, input().split()) map(int, input().split()) m x = [0]*n [0]*n x a = 0 0 a l  =[0]*m [0]*m l r = [0]*m [0]*m r n,m = map(int, input().split()) map(int, input().split()) n a = min(r)-max(l)+1 min(r)-max(l)+1 a
n,m = map(int, input().split())
x = [0]*n
a = 0
l  =[0]*m
r = [0]*m
for i in range(m):
  l[i],r[i]=map(int,input().split())
a = min(r)-max(l)+1
print(max(0,a))