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

'''
S = []
for i in range(K):
    L,R = map(int,input().split())
    for j in range(L,R + 1):
        S.append(j)
'''


LR = [list(map(int,input().split())) for _ in range(K)]
L = [0]*N
for i in range(N):
    if i == 0:
        L[0] = 1
    else:#i>=1のとき
        for j in range(K):#それぞれの区間に対して
            if i - LR[j][0] >= 0:
                L[i] +=sum(L[max(i - LR[j][1],0) : i - LR[j][0] + 1])
               
print(L[N-1]%998244353)
            