import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

mod = 998244353

n, k = map(int, input().split())
s = set()
for _ in range(k):
    l, r = map(int, input().split())
    for i in range(l, r + 1):
        s.add(i)

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

for i in range(1, n + 1):
    for j in range(i):
        if i - j in s:
            dp[i] += dp[j]
            dp[i] %= mod

print(dp[-2])
    