N, M = map(int, input().split())
l, r = 1, N
for i in range(M):
  L, R = map(int, input().split())
  l, r = max(l, L), min(r, R)
if r - l >= 0:
  print(r - l + 1)
else:
  print(0) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M l, r = 1, N l 1 r N for i in range(M):
  L, R = map(int, input().split())
  l, r = max(l, L), min(r, R) i range(M) range M L, R = map(int, input().split()) L map(int, input().split()) map int input().split() ().split () input split R l, r = max(l, L), min(r, R) l max(l, L) max l L r min(r, R) min r R if r - l >= 0:
  print(r - l + 1)
else:
  print(0) r - l >= 0 r - l r l 0 print(r - l + 1) print r - l + 1 r - l r l 1 print(0) print 0 l, r = 1, N 1 l r = max(l, L), min(r, R) min(r, R) r M = map(int, input().split()) map(int, input().split()) M r = 1, N N r R = map(int, input().split()) map(int, input().split()) R l, r = max(l, L), min(r, R) max(l, L) l L, R = map(int, input().split()) map(int, input().split()) L N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
l, r = 1, N
for i in range(M):
  L, R = map(int, input().split())
  l, r = max(l, L), min(r, R)
if r - l >= 0:
  print(r - l + 1)
else:
  print(0)