n, k = map(int, input().split())
lr = [list(map(int,input().split())) for _ in range(k)]
s = []
mod = 998244353

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

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

for i in range(n):
    for j in s:
        li[i] += li[i-j]
        li[i] %= mod

print(li[n-1])