n,k =map(int,input().split())
s =[]
for i in range(k):
    l,r=map(int,input().split())
    s+=(list(range(l,r+1)))
S= set(s)
print(S)

mod = 998244353

# How many are there to climb
step = [0] * (n+1)


for i in range(1,n+1):
    for s in S:
        if i+s<=n:
            step[i+s]+=1
print(step[n])