N, K = map(int, input().split())

Q = 998244353
S = [0] * (N + 1)

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

P = [0] * N
P[0] = 1

for i in range(1, N):
    for j in range(i):
        P[i] += S[i-j] * P[j]
        P[i] = P[i] % Q

print(P[-1])