import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 998244353
n, k = map(int, input().split())
s = set()
for i in range(k):
    a, b = map(int, input().split())
    s.update(range(a, b + 1))
s = sorted(list(s))

dp = [0] + [0] * n
dp[1] = 1
for i in range(1, n + 1):
    for j in s:
        if i + j > n:
            break
        else:
            dp[i + j] = (dp[i + j] + dp[i]) % MOD
print(dp[n])
