N, K =map(int, input().split())
LR = [map(int, input().split()) for _ in range(K)]
L, R = [list(i) for i in zip(*LR)]
list=[]
count=0
for j in range(K):
  for num in range(L[j],R[j]+1):
    list.append(num)
from collections import deque
que = deque()
for i in range(len(list)):
    que.append(list[i])

while que:
    seq = que.popleft()
    if sum(seq) == N:
      count+=1
    else:
      for i in range(list.index(seq[-1]), len(list)):
           seq_next = seq + list[i]
           que.append(seq_next)
print(count)