n, k = map(int, input().split())
mod = 998244353
section = set()
dp = [0]*n
dp[0] = 1

for i in range(k):
  l, r = map(int, input().split())
  section = section.union(set(range(l, r+1)))
  

for i in range(n):
  for step in section:
    x = dp[i] % mod
    if i + step < n:
      dp[i+step] += x
      
print(dp[-1] % mod)