N, K = map(int, input().split())
lr = []
dp = [0] * N
dp[0] = 1

for _ in range(K):
  l, r = map(int, input().split())
  lr += list(range(l, r + 1))
  
for i in range(0, N - 1):
  if dp[i] == 0:
    continue
    
  for j in range(len(lr)):
    if i + lr[j] > N - 1:
      continue
      
    dp[i + lr[j]] += dp[i]
    
print(dp[N - 1] % 998244353)