temparr = input()
temparr = temparr.split()
n = int(temparr[0])
k = int(temparr[1])
dicts = {}
dp = [0 for _ in range(n + 2)]
dp[1] = 1 
arr = []
dicts = {}
for kk in range(k):
    temparr = input()
    temparr = temparr.split()
    f = int(temparr[0])
    l = int(temparr[1]) + 1 
    for i in range(f,l):
        if i not in dicts:
            dicts[i] = 1 
for key, value in dicts.items():
    arr.append(key)
arr = sorted(arr)
#print(arr)
for i in range(1, n + 1):
    if dp[i] == 0:
        continue 
    for j in arr:
        index = i + j 
        if index > n :
            break 
        dp[index] += dp[i]
print(dp[n])
    
    
    
    
    
        