import sys
input = sys.stdin.readline
N, K = map(int, input().split())
 
LR = [list(map(int, input().split())) for _ in range(K)]
 
m = 998244353
 
S = []
for lr in LR:
    S.extend(range(lr[0], lr[1]+1))
 
p = []
 
for i in range(N):
    if i == 0 :
        p.append(1)
    else:
        t = 0
        for s in S:
            if s <= i:
                t += p[i-s]
        p.append(t%m) 
 
print (p[N-1])
