n, k = map(int, input().split())
sec = [list(map(int, input().split())) for _ in range(k)]
sec.sort()

mod = 998244353

dp = [0] * n
dp[0] = 1
dp[1] = 1
for i in range(1, n-1):
    tmp = 0
    for j in range(k):
        l, r = sec[j]
        if (i + 1) - l >= 0:
            tmp = (tmp + dp[i+1-l]) % mod
        if i - r >= 0:
            tmp = (tmp - dp[i-r]) % mod
    
    dp[i+1] = (dp[i] + tmp) % mod

print(dp[n-1])