n, k = [int(x) for x in input().split()]
S = set()
for _ in range(k):
    l, r = [int(x) for x in input().split()]
    for i in range(l, r + 1):
        S.add(i)
S = list(sorted(S))
memo = {0: 1}
for i in range(1, n):
    memo[i] = sum(memo[i - s] for s in S if i - s >= 0) % 998244353
print(memo[n - 1])
