N, K = map(int, input().split())
LL = []
RR = []
mod = 998244353
for i in range(K):
    L, R = map(int, input().split())

    LL.append(L)
    RR.append(R + 1)


keep = 0
dp = [0] * 2 * N
dp[N] = 1
for i in range(1, N):
    for j in range(K):

        keep = (keep + dp[N + i - LL[j]] - dp[N + i - RR[j]]) % mod 

    dp[N + i] = (dp[N + i] + keep) % mod
print(dp[2 * N - 1] % mod)
