import numpy as np
n, k = map(int, input().split())
dp = np.array([0 for i in range(n)])
 
s = []
for i in range(k):
  l, r = map(int, input().split())
  s.append([l,r])
  
dp[0] = 1
for i in range(n):
  for l,r in s:
    dp[i+l:i+r] = (dp[i+l:i+r] + dp[i]) % 998244353

print(dp[-1])
