N,K=list(map(int,input().split()))
L=[]
for i in range(K):
    L.append(list(map(int,input().split())))
import sys
sys.setrecursionlimit(10**6)
S=[]
for i in range(K):
    S.extend(j for j in range(L[i][0],L[i][1]+1))
S=sorted(S)
import numpy as np
D=np.zeros(N+1)
D[1]=1
for i in range(2,N+1):
    for j in range(1,i):
        if (i-j) in S:
            D[i]+=D[j]
print(D[N]%998244353)