N, K = map(int, input().split())
LRs = [tuple(map(int, input().split())) for _ in range(K)]

MOD = 998244353

dp = [0] * (N + 1)
dp_csum = [0] * (N + 2)
dp[1] = 1
dp_csum[2] = 1
for i in range(2, N + 1):
    for L, R in LRs:
        dp[i] += dp_csum[max(0, i - L + 1)] - dp_csum[max(0, i - R)]
        dp[i] %= MOD
    dp_csum[i + 1] = dp_csum[i] + dp[i]
    dp_csum[i + 1] %= MOD

# print(dp)
# print(dp_csum)

print(dp[N])