n, k = map(int, input().split())
MOD = 998244353

lr = []
for _ in range(k):
    l, r = map(int, input().split())
    lr += (list(range(l, r + 1)))

lr.sort()

dp = [0] * n

dp[0] = 1

for i in range(n - 1):
    for k in lr:
        if i + 1 - k >= 0:
            dp[i + 1] += dp[i + 1 - k]
            dp[i + 1] %= MOD

print(dp[-1])