n,k = map(int,input().split())
mod = 998244353

s = []
for _ in range(k):
  l,r = map(int,input().split())
  s.extend(range(l,r+1))

s.sort()
dp = [0]*(n+1)
dp[1] = 1

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