N, K = map(int, input().split())
D = []
MOD = 998244353

for i in range(K):
    l, r = map(int, input().split())
    D.append((l, r))

dp = [0] * N
dp[0] = 1
for i in range(1, N):
    for l, r in D:
        if i - l < 0:
            continue
        r = max(0, i - r)
        l = i - l + 1
        dp[i] += (dp[i] + sum(dp[r:l])) % MOD

print(dp[N-1])
