import numpy as np
N,K = map(int, input().split())

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

step = np.zeros(N+1)
step[1] = 1

for j in range(1,N):
    for l,r in S:
        if j + l > N:
            continue
        r_ = min(j+r+1,N+1)
        step[j+l: r_] += step[j]
        step[j+l:r_] %= 998244353
    
print(int(step[N]))