N, K = map(int, input().split())
dp = [0] *  (2 * 10 ** 5 + 1)
S = set()
for i in range(K):
    l, r = map(int, input().split())
    for v in range(l, r + 1):
        S.add(v)

dp[1] = 1
MOD = 998244353
for i in range(1, N):
    for v in S:
        if i + v <= N:
            dp[i + v] += dp[i]
            dp[i + v] %= MOD

print(dp[N])

