n, k = map(int, input().split())
mod = 998244353
ans = [0]*(n*2)
ans[0] = 1
c = []


for i in range(k):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        c.append(j)

for i in range(n):
    for j in c:
        ans[i + j] += ans[i]%mod

print(ans[n - 1]%mod)