from collections import defaultdict

N, K = map(int, input().split())
LRs = [tuple(map(int, input().split())) for _ in range(K)]
mod = 998244353

dd = defaultdict(int)
dd[N] = 1

for _i in range(N-1):
    i = N-1 - _i
    for l, r in LRs:
        for d in range(l, r+1):
            dd[i] = (dd[i] + dd[i+d]) % mod

print(dd[1])

