from sys import stdin,stdout
n,k=list(map(int,stdin.readline().split()));l=[];s=[];M=998244353
for _ in range(k):
    x,y=list(map(int,stdin.readline().split()))
    l+=[[x,y]]
for stp in range(n+1):
    for x,y in l:
        if x<=stp<=y:s+=[stp]
dp=[0]*(n+1);dp[1]=1
for i in range(2,n+1):
     for steps in s:
         if steps>=i:break
         dp[i]=(dp[i]+dp[i-steps])%M
print(dp[n])