MOD = 998244353
N, K = map(int, input().split())
s = set()
for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        s.add(j)
m = max(s)

p = [0] * (N + m)
p[m] = 1
for i in range(m + 1, N + m):
    c = 0
    for j in s:
        c += p[i - j]
    p[i] = (c % MOD)
    

print(p[N + m -1] % MOD)
