# 配るDP
def resolve():
  base = 998244353
  N, K = map(int, input().split(" "))

  LRs = []
  for _ in range(K):
    (L, R) = map(int, input().split(" "))
    LRs.append((L, R))

  dp = [0] * (N+1)
  dp_sum = [0] * (N+1)
  dp[1] = 1
  dp_sum[1] = 1

  for i in range(1, N+1):
    dp_sum[i] = dp[i] + dp_sum[i-1]
    if dp_sum[i] > base:
      dp_sum[i] %= base
    for lr in LRs:
      left = i + lr[0]
      right = i + lr[1] + 1
      if left <= N:
        dp[left] += dp_sum[i]
      if right <= N:
        dp[right] -= dp_sum[i]
    
  print(dp[-1]%base)

if __name__ == "__main__":
  resolve()