import sys
sys.setrecursionlimit(30000)
M=998244353
y=lambda:map(int,input().split())
n,k=y()
s=set()
for i in range(k):
    a,b=y()
    for j in range(a,b+1):s.add(j)
d={1:1}
def v(n):
    if n<1:return 0
    if n in d:return d[n]
    r=sum(v(n-i)for i in s)%M
    d[n]=r
    return r
print(v(n))