n , m = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(m)]

mi = 0
ma = n
for i in range(m):
  mi = max(mi, lr[i][0])
  ma = min(ma, lr[i][1])
  
  
if ma-mi>=0:
  print(ma-mi+1)
else:
  print(0) n , m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m list(map(int, input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split lr = [list(map(int, input().split())) for i in range(m)] lr [list(map(int, input().split())) for i in range(m)] mi = 0 mi 0 ma = n ma n for i in range(m):
  mi = max(mi, lr[i][0])
  ma = min(ma, lr[i][1])
  
   i range(m) range m mi = max(mi, lr[i][0]) mi max(mi, lr[i][0]) max mi lr[i][0] [i] lr i 0 ma = min(ma, lr[i][1]) ma min(ma, lr[i][1]) min ma lr[i][1] [i] lr i 1 if ma-mi>=0:
  print(ma-mi+1)
else:
  print(0) ma-mi>=0 ma-mi ma mi 0 print(ma-mi+1) print ma-mi+1 ma-mi ma mi 1 print(0) print 0 n , m = map(int, input().split()) map(int, input().split()) n ma = n n ma mi = max(mi, lr[i][0]) max(mi, lr[i][0]) mi lr = [list(map(int, input().split())) for i in range(m)] [list(map(int, input().split())) for i in range(m)] lr mi = 0 0 mi ma = min(ma, lr[i][1]) min(ma, lr[i][1]) ma m = map(int, input().split()) map(int, input().split()) m
n , m = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(m)]

mi = 0
ma = n
for i in range(m):
  mi = max(mi, lr[i][0])
  ma = min(ma, lr[i][1])
  
  
if ma-mi>=0:
  print(ma-mi+1)
else:
  print(0)