import sys
sys.setrecursionlimit(1000000)

n, k = map(int, input().split())
s = set()
for _ in range(k):
  l, r = map(int, input().split())
  s |= set(range(l, r+1)) 

s = sorted(s)
MOD = 998244353  
  
dp = [-1] * n
dp[0] = 1

def ans(i):
  if dp[i] == -1:
    dp[i] = sum( 
      ans(i - si)
      for si 
      in s
      if i >= si
    ) % MOD
  return dp[i]

print(ans(n-1))