import sys
input = sys.stdin.readline

N,K=map(int,input().split())
steps = []
for _ in range(K):
    l,r = map(int,input().split())
    for i in range(l,r+1):
        steps.append(i)

steps = tuple(steps)
mod = 998244353

ans = [1]
for i in range(1,N):
    c = 0
    for s in steps:
        if i - s < 0:
            continue
        c += ans[i-s]
        c %= mod
    ans.append(c)

print(ans[N-1])