div = 998244353
n, k = map(int, input().split())
dp = [0] * (n + 1)
S = set()
for i in range(k):
    l, r = map(int, input().split())
    for x in range(l, r+1):
        S.add(x)
dp[1] = 1
for i in range(2, n+1):
    for s in S:
        idx = i - s
        if idx < 1:
            break
        dp[i] += dp[idx]
        dp[i] %= div
print(dp[-1])
