n, k = map(int, input().split())
s = [] 
for i in range(k):
    s.append(list(map(int, input().split())))

dp = [0 for _ in range(n)]
dp[0] = 1

leng = 0
for i in range(1,n):
    for j in s:
        leng = j[1] - j[0]
        dp[i] += sum(dp[max(0, i-leng-j[0]):max(0,min(n, i-j[0]+1))])

print(dp[-1])