nk=map(int,input().split())
a=[]
for i in range(k):
  lr=map(int,input().split())
  for i in range(l,r+1):
    a.append(i)
a=list(set(a))
dp=[0]*n
dp[0]=1
for i in range(1,n):
  for j in a:
    if i>=j:
      dp[i]+=dp[i-j]
return dp[-1]
