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

s = set()
for i in range(k):
    l, r = map(int, input().split())
    for i in range(l, r+1):
        s.add(i)

mod = 998244353
col = list(s)
counts = [0]*(n+1)
for i in range(1, n+1):
    for c in col:
        if c > i:
            break
        if c == i:
            counts[i] += 1
            continue
        else:
            counts[i] += counts[i-c] % mod

print(counts[n-1] % mod)