n,k= list(map(int, input().split()))
INF=998244353
s=[]
for i in range(k):
    j,k=map(int,input().split())
    s.append([l for l in range(j,k+1)])
pattern=[0 for i in range(n)]
pattern[0]=1
ls=len(s)
s.sort()
for i in range(1,n):
    tmp=0
    for j in s:
        if i-j[0]<0:
            break
        else:
            tmp+=sum(pattern[max(i-j[1],0):i-j[0]])
        tmp%=INF
    pattern[i]=tmp
print(pattern[-1])