'''go to every index and then run a index - 1 to 1 for it and check whether the proposed number lies somewhere or not'''
n,k = tuple(map(int,input().split()))
boolean = [False]*n
for _ in range(k):
  l,r = tuple(map(int,input().split()))
  for num in range(l,r+1):
    boolean[num] = True;
dp = [0 for _ in range(n+1)]
boolean = [False for _ in range(n+1)]
for i in range(2,n+1):
  for lower in range(1,i):
    if boolean[lower]:
    	start = i - lower
        dp[i] += dp[start]
print(dp[n])
    