n,m = map(int, input().split())
ls = []
rs = []
for _ in range(m):
  l,r = map(int, input().split())
  ls.append(l)
  rs.append(r)
  
ans = min(rs) - max(ls) + 1

if ans > 0: print(ans)
else: print(0) n,m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m ls = [] ls [] rs = [] rs [] for _ in range(m):
  l,r = map(int, input().split())
  ls.append(l)
  rs.append(r)
   _ range(m) range m l,r = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r ls.append(l) ls.append ls append l rs.append(r) rs.append rs append r ans = min(rs) - max(ls) + 1 ans min(rs) - max(ls) + 1 min(rs) - max(ls) min(rs) min rs max(ls) max ls 1 if ans > 0: print(ans)
else: print(0) ans > 0 ans 0 n,m = map(int, input().split()) map(int, input().split()) n r = map(int, input().split()) map(int, input().split()) r m = map(int, input().split()) map(int, input().split()) m ls = [] [] ls ans = min(rs) - max(ls) + 1 min(rs) - max(ls) + 1 ans rs = [] [] rs l,r = map(int, input().split()) map(int, input().split()) l
n,m = map(int, input().split())
ls = []
rs = []
for _ in range(m):
  l,r = map(int, input().split())
  ls.append(l)
  rs.append(r)
  
ans = min(rs) - max(ls) + 1

if ans > 0: print(ans)
else: print(0)