n, k = map(int, input().split())
mod = 998244353
ansList = [0] * (n + 1)
numList = []
for x in range(k):
    l, r = map(int, input().split())
    for id in range(l, r+1):
        numList.append(id)
numList.sort()

ansList[1] += 1
for id in range(1,n+1):
    for x in numList:
        if id + x > n: break 
        ansList[id + x] += ansList[id]
print(ansList[n] % mod)