import numpy as np

m = 998244353
N, K = map(int, input().split())
L = []
R = []
for K in range(K):
    l , r = map(int, input().split())
    L.append(l)
    R.append(r)

s = []
for i in range(len(L)):
    tmp = [n for n in range(L[i], R[i]+1)]
    s += tmp

s.sort()
ans = [1]
for i in range(1,N):
    tmp = 0
    for ss in s:
        if len(ans) < ss:
            break
#         print("i ", i)
#         print(ss)
        tmp += ans[i - ss]%m
#         print(ans)
    ans.append(tmp%m)

print(ans[-1])