mod = 998244353
n, k = map(int, input().split())
s = []
for _ in range(k):
    l, r = map(int, input().split())
    s.extend([x for x in range(l, r+1)])

score = [0 for _ in range(n)]
score[0] = 1
for i in range(n):
    for x in s:
        if i+x >= n:
            continue
        score[i+x] = (score[i]+score[i+x])%mod

print(score[n-1])