n,k  = map(int, input().split())
s = []
alist = [0] * 1_000_000
alist[1] = 1    # start point

for i in range(k):
    s_i = list(map(int, input().split()))
    s.extend([x for x in range(s_i[0], s_i[1] + 1)])

for i in range(n):
    if alist[i] == 0: continue
    for j in range(len(s)):
        alist[i+s[j]] += alist[i]
print(alist[n] % 998244353)