P = 998244353
N, K = map(int, input().split())
X = []
for _ in range(K):
    l, r = map(int, input().split())
    X.append((l-1, r))

A = [1] + [0] * N
S = [0, 1] + [0] * N
for i in range(1, N):
    for l, r in X:
        A[i] += S[max(i-l, 0)] - S[max(i-r, 0)]
        A[i] %= P
    S[i+1] = (S[i] + A[i]) % P

print(A[N-1])