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