def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

from sys import setrecursionlimit
setrecursionlimit(10**6)

N= 998244353
def find1(ar,n):
    if n==0:
        return 1
    elif n<0:
        return 0
    elif d[n]!=0:
        return d[n]
    s=0
    for i in ar:
        s=(s+find1(ar,n-i)%N)%N
    d[n]=s
    return s

n,k=sep()
ar=[]
from collections import defaultdict
d=defaultdict(int)
for i in range(k):
    l,r=sep()
    ar+=list(range(l,r+1))
ar.sort()
t=n
while(t>100):
    find1(ar,t)
    t//=2
print(find1(ar,n-1))
