

N, K = map(int, input().split())

mod = 998244353

dp = [0] * N
dp[0] = 1

LR = [list(map(int, input().split())) for i in range(K)]
X = [0] * K

for i in range(1, N):
  for j in range(K):
    if i - LR[j][0] >= 0:
      X[j] += dp[i - LR[j][0]]
    if i - LR[j][1] > 0:
      X[j] -= dp[i - LR[j][1] - 1]
    X[j] %= mod
  dp[i] = sum(X) % mod
print(dp[-1])
    