n, k = map(int,input().split())
S = []
mod = 998244353
for i in range(k):
  l,r  = map(int,input().split())
  S += list(range(l,r+1))
S = sorted(S)
dp = [0]*(n+1)
#print(S)
dp[1] = 1
for i in range(2,n+1):
  for s in S:
    if i-s<1:
      break
    dp[i] += dp[i-s]
    dp[i] %= mod
    
print(dp[n])
