n,k= list(map(int, input().split()))
INF=998244353
s=[]
for i in range(k):
    j,jj=map(int,input().split())
    s.append([l for l in range(j,jj+1)])
pattern=[0 for i in range(n)]
pattern[0]=1
ls=len(s)
memo=[0 for i in range(k)]
s.sort()
for i in range(1,n):
    tmp=0
    for index,j in enumerate(s):
        if i-j[0]<0:
            break
        elif i-j[-1]>0:
            memo[index]+=pattern[i-j[0]]
            memo[index]-=pattern[i-j[-1]-1]
            if memo[index]<0:
                memo[index]+=INF
        else:
            memo[index]+=pattern[i-j[0]]

        #tmp+=sum(pattern[max(i-j[-1],0):i-j[0]+1])
        memo[index]%=INF
    pattern[i]=sum(memo)
print(pattern[-1])