n, k = map(int, input().split())
MOD = 998244353

lr = []
for _ in range(k):
    l, r = map(int, input().split())
    lr += (list(range(l, r + 1)))

lr.sort()
lr = np.array(lr)

dp = np.zeros(n + n, dtype=np.int64)
dp[0] = 1
dp2 = dp.copy()

for i in range(n):
    idx = i + lr
    dp2[idx] += dp[i]
    dp2 %= MOD
    dp = dp2

print(dp[n - 1])