n, k = map(int, input().split())
MOD = 998244353
a = [list(map(int, input().split())) for _ in range(k)]

dp = [0] * (n + 1)

dp[0] = 0; dp[1] = 1

for i in range(2, n+1):
    dp[i] = dp[i-1]
    for x, y in a:
        l = i - y; r = i - x
        l = max(l, 0); r = min(r, i-1)
        dp[i] = (dp[i] + (dp[r] - (dp[l - 1] if l > 0 else 0))) % MOD
            
print(dp[-1] - dp[-2])
