import numpy as np

mod = 998244353

N, K = map(int, input().split())
LR = []

for _ in range(K):
    l, r = map(int, input().split())
    LR.append((l, r))

dp = np.array([0] * (N+1))
dp[1] += 1

for i in range(1, N+1):
    now = dp[i] % mod
    if now:
        for l, r in LR:
            try:
                dp[i+l:i+r+1] += now
            except:
                break

print(dp[-1] % mod)
