N, K = map(int,input().split())
S = set()
for _ in range(K):
    l , r = map(int,input().split())
    for q in range(l,r+1):
        S.add(q)
ps = [0] * N
for a in S:
    if a < N:
        ps[a] = 1
for i in range(N):
    for a in S:
        if i-a >= 0:
            ps[i] += ps[i-a]
print(ps[N-1] % 998244353)
    