MOD = 998244353

n, k = list(map(int, input().split()))
lr = [list(map(int, input().split())) for _ in range(k)]

s = set()
for l, r in lr:
  for d in range(l, r + 1):
    s.add(d)


dp = [0] * n
dp[0] = 1

for i in range(n):
  for d in s:
    if i + d >= n:
      continue
    dp[i + d] += dp[i]

print(dp[n - 1] % MOD)
