N,K = list(map(int,input().split()))
p = 998244353
LR = []
for i in range(K):
    LR.append(list(map(int,input().split())))
T = [0]*(2*N+10)
T[1] = 1
S = [0]*(2*N+10)
S[1] = 1
S[2] = -1
for i in range(1,N):
    for j in range(K):
        L,R = LR[j]
        S[i+L]=S[i+L]+T[i]
        S[i+R+1]=S[i+R+1]-T[i]
    T[i+1] = (T[i]+S[i+1])%p
print(T[N])