# -*- coding: utf-8 -*-
n, k = map(int, input().split())
mod = 998244353
s = set()
for _ in range(k):
    l, r = map(int, input().split())
    s = s.union(set(list(range(l, r+1))))

s = sorted(list(s))
leap = [0 for _ in range(n + 1)]
leap[1] = 1
for i in range(1, n):
    base = leap[i]
    if base == 0:
        continue
    for j in s:
        if i + j > n:
            break
        leap[i+j] += base
        leap[i+j] %= mod

print(leap[n])
