import sys
input = sys.stdin.readline

mod = 998244353

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

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

s = set(s)

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

s = sorted(list(s))


for i in range(n):
    if dp[i] == 0:
        continue
    for s_ele in s:
        if s_ele + i > n:
            break
        dp[i+s_ele] += dp[i]

print(dp[n-1]%mod)