mod = 998244353

n, k = input().split()
n, k = int(n), int(k)
s = []
for i in range(k):
    l, r = input().split()
    for j in range(int(l), int(r)+1):
        s.append(j)

f = [1]
for i in range(1, n):
    sum = 0
    for j in s:
        if j <= i:
            sum += f[i-j]
            sum %= mod
    f.append(sum)

print(f[n-1])