import sys
sys.setrecursionlimit(10**6)
mod=998244353
N,K=map(int,input().split())
S1=[]
for _ in range(K):
    l,r=map(int,input().split())
    S1+=list(range(l,r+1))
S=sorted(S1)
dp=[0]*(N+1)
def Leaping_Tak(n,S):
    if dp[n]!=0:
        return dp[n]
    if n==0:
        return 1
    if 0<n<S[0]:
        return 0
    x=0
    for s in range(S):
        if n-s > 0 and dp[n-s]==0:
             x += Leaping_Tak(n-s,S)
        elif n-s > 0 and dp[n-s]!=0:
            x+=dp[n-s]
    dp[n]=x
    return x%mod

ans=Leaping_Tak(N-1,S)
print(ans)