# 解説を見て解き直し
N, K = [int(x) for x in input().split()]

ranges = [tuple(int(x) for x in input().split()) for _ in range(K)]
ranges.sort()
p = 998244353

dpsum = [0] * (N + 1)
dpsum[1] = 1

for i in range(2, N + 1):
    dp = 0
    for l, r in ranges:
        rj = max(0, i - l)
        lj = max(1, i - r)
        dp += dpsum[rj] - dpsum[lj - 1]
        dp %= p
    dpsum[i] = dpsum[i - 1] + dp
    dpsum[i] %= p

print(dp)