MOD = 998244353
N, K = map(int, input().split())
LRs = []
sums = []
for _ in range(K):
    l, r = map(int, input().split())
    LRs.append([l, r])
    sums.append(1 if l <= 1 <= r else 0)

dp = [0] * (N * 2)
dp[1] = 1

for i in range(2, N+1):
    dp[i] = sum(sums) % MOD
    for k in range(K):
        l, r = LRs[k]
        sums[k] = (sums[k] + dp[i-l+1] - dp[i-r]) % MOD
print(dp[N])
