import sys
sys.setrecursionlimit(200000)

N,K=map(int,input().strip().split())
inf=998244353
S=[]
for _ in range(K):
    L,R=map(int,input().strip().split())
    for i in range(L,R+1):
        S.append(i)

dp=[-1 for _ in range(N)]
dp[0]=1
def rec(n,S,dp):
    if dp[n-1]!=-1:
        return dp[n-1]
    else:
        dp[n-1]=0
        for j in range(len(S)):
            x=n-S[j]
            if x>0:
                if dp[x-1]!=-1:
                    dp[n-1]+=dp[x-1]%inf
                else:
                    dp[x-1]=rec(x,S,dp)
                    dp[n-1]+=dp[x-1]%inf
        dp[n-1]=dp[n-1]%inf
        return dp[n-1]

print(rec(N,S,dp))