import sys

input = sys.stdin.readline

mod = 998244353

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

lr = [tuple(map(int, input().split())) for _ in range(k)]
lr.sort()

leaplist = []
for l, r in lr:
    leaplist += list(range(l, r + 1))
pass

dp = [0] * n
dp[0] = 1
for i in range(1, n):
    for l in leaplist:
        if i < l:
            break
        dp[i] += dp[i - l]
        dp[i] %= mod
print(dp[-1])
