from sys import stdin
def I():
    return stdin.readline().rstrip()
def MI():
    return map(int,stdin.readline().rstrip().split())
def LI():
    return list(map(int,stdin.readline().rstrip().split()))
#main part
n,k=MI()
inf=998244353
S=[0]*(n+1)
for _ in range(k):
    l,r=MI()
    if l==r:
        S[l]=1
    else:
        for i in range(l,r+1):
            S[i]=1
s=[]
for i in range(n):
    if S[i]==1:
        s.append(i)
dp=[0]*(2*(10**5)+1)
for i in range(1,len(dp)):
    if i in s:
        dp[i+1]+=1
    for j in range(len(s)):
        if i-s[j]<0:
            break
        else:
            dp[i]+=dp[i-s[j]]
print(dp[n]%inf)