N, K = map(int, input().split())
L, R = [], []
for _ in range(K):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
mod = 998244353

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

for i in range(N):
  for l, r in zip(L, R):
    if i - l >= 0:
      dp[i] = (dp[i] + sum(dp[max(0, i - r):i - l + 1])) % mod

print(dp[-1])