N, K = map(int, input().split())
LL = []
RR = []
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 += (dp[N + i - LL[j]] - dp[N + i - RR[j]])

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