# 配る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[1] = 1

  for i in range(1, N):
    dp[i] += dp[i-1]

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

if __name__ == "__main__":
  resolve()