N,K=map(int,input().split())
X=[list (map(int,input().split())) for i in range(K)]
Y=[]
for i in range(K):
  for j in  range(X[i-1][0],X[i-1][1]+1):
    Y.append(j)
  else:
else:
  
Z=[0]*(max(Y)-1)+[1]
for i in range(N-1):
  a=0
  for j in Y:
    a=a+Z[len(Z)-j]
  break
  Z.append(a):
break
  
print(Z(-1))
