N, K = map(int, input().split())
S = []
for _ in range(K):
    x, y = map(int, input().split())
    for i in range(x, y+1):
        S.append(i)
S.sort()
S_use = []
len_S = len(S)
now = 0
ALL = [0] * (N)
ALL[0] = 1
for i in range(N):
    if now < len_S:
        if S[now] < i+1:
            S_use.append(S[now])
            now += 1
    for k in S_use:
        ALL[i] += ALL[i-k]
        ALL[i] = ALL[i] % 998244353
print(ALL[N-1])