n, k = map(int, input().split())
dp = [0 for i in range(n)]

s = []
for i in range(k):
  l, r = map(int, input().split())
  s.extend(list(range(l,r+1)))

s = sorted(s)

dp[0] = 1
for i in range(n):
  for a in s:
    if i+a < n:
      dp[i+a] = (dp[i+a] + dp[i]) % 998244353

print(dp[-1])
