N, K = map(int, input().split())
ints = []

for _ in range(K):
  L, R = map(int, input().split())
  ints = list(set(ints) | set(list(range(L, R + 1))))
  
import numpy as np
ints = np.array(ints)
orig_ints = ints.copy()
ints += 1
count = 0
count += (ints == N).sum()



for k in range(N):
  y, x = np.meshgrid(orig_ints, ints)
  ints = y + x
  #print(y.shape, x.shape)
  #print(ints)
  count += (ints == N).sum()
  
print(count)
  