n, k = map(int, input().split())
mod = 998244353
lr = []
s = set()
for i in range(k):
  l,r = map(int, input().split())
  for j in range(l,r+1):
    s.add(j)

dp = [0 for i in range(n+1)]
dp[1] = 1
for i in range(1,n+1):
  for j in s:
    if i-j < 1:
      continue
    dp[i] += dp[i-j]
    dp[i] %= mod
# print (dp)
print (dp[n])