
def main():
  n, k = map(int, input().split())

  n -= 1

  S = sorted({
    i
    for l, r in [map(int, input().split()) for _ in range(k)]
    for i in range(l, r + 1)
  })

  dp = [None] * (n+1)
  dp[0] = 1

  def cal(num):
    total = 0
    for s in S:
      if s > num: break

      next_num = num - s

      total += dp[next_num] or cal(next_num)

    dp[num] = total

    return total

  print(cal(n) % 998244353)





main()
