n, k = map(int, input().split())
div = 998244353
S = []
for i in range(k):
  S.append(tuple(map(int, input().split())))
#print(S)###

dp = [0] * (2 * n)
wa = [0] * k

dp[n] = 1
#print(dp)

for i in range(n + 1, 2 * n):
  for j in range(k):
    wa[j] += (dp[i - S[j][0]] - dp[i - S[j][1] - 1])
    dp[i] += wa[j]
  dp[i] %= div
#print(dp)
print(dp[-1])