n,k = map(int,input().split())
s=[]
dp=[0]*(n+5)
for i in range(k):
     l,r =map(int,input().split())
     for j in range(l,r+1):
         s.append(j)
          
s.sort()
dp[0]=1
dp[s[0]]=1
for i in range(s[0]+1,n+4):
    for j in s:
        if j>i:
            break
        else:
            dp[i]+= dp[i-j] % 998244353
        dp[i] %= 998244353
print(dp[n-1])