mod = 998244353

N,K = map(int,input().split())
O = []
for i in range(K):
    O.append(tuple(map(int,input().split())))

A = [0] * (N+1)
A[0] = 1
B = [0] * (N+1)
aaa = 0
for i in range(N):
    for L,R in O:
        if i + L < N:
            B[i + L] += A[i]
            if i + R < N:
                B[i + R + 1] -= A[i]
    aaa += B[i + 1]
    A[i+1] = aaa % mod

print(A[N-1])