MOD = 998244353
N, K = map(int, input().split())
LR = [tuple(map(int, input().split())) for i in range(K)]

dp = [0] * (N+1)
dp[1] = 1
for i in range(1, N):
  dp[i] += dp[i-1]
  dp[i] %= MOD
  for l, r in LR:
    ll = i + l
    rr = i + r
    if ll <= N:
      dp[ll] += dp[i]
      dp[ll] %= MOD
    if rr < N:
      dp[rr+1] -= dp[i]
      dp[rr+1] %= MOD

print(dp[-1])