mod = 998244353
N, K = map(int,input().split())
S = []
for i in range(K):
    l,r = map(int,input().split())
    for j in range(r-l+1):
        S.append(l+j)
A = [0]*N
A[0] = 1
for i in range(N):
    for j in range(len(S)):
        if i - S[j]  >= 0:
            A[i] = (A[i] + A[i-S[j]]) % mod
print(A[-1])
