n,k = map(int,input().split())
s = []
for i in range(k):
    a,b = map(int,input().split())
    for i in range(a,b+1):
        s += [i]


s = list(set(s))

ans = [0] * (n+1)
ans[1] = 1

for i in range(2,n+1):
    for j in range(len(s)):
        if i-s[j] > 0:
            ans[i] += ans[i-s[j]]


print(ans[n]%998244353)
