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

MOD = 998244353

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

for i in range(n):
  for l, r in LR:
    for j in range(l, r + 1):
      if i - j >= 0:
        dp[i] += dp[i - j]
        dp[i] %= MOD

print(dp[-1])