
N, K = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(K)]
MOD = 998244353

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

for i in range(1, N):
    for l, r in X:
        for k in range(l, r + 1):
            if i + k > N:
                break
            dp[i + k] += dp[i]
            dp[i + k] %= MOD

print(dp[-1])
