mod = 998244353
N = int(1e6)
n, k = map(int, input().split())
seg = []
for i in range(k):
    seg.append(tuple(map(int, input().split())))
pref = [1] + [0] * N
for i in range(1, n):
    pref[i] += pref[i - 1]
    for x, y in seg:
        pref[i] += pref[i - x] - pref[i - y - 1] + mod
    pref[i] %= mod
print((pref[n - 1] - pref[n - 2] + mod) % mod)
