from collections import deque
import sys, copy, itertools,heapq
input = sys.stdin.readline

n,k = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(k)]
S = []
for i in range(k):
  a = LR[i][1] - LR[i][0]
  b = LR[i][0]
  for j in range(a+1):
    S.append(b)
    b += 1
S.sort()
    
DP = [0] * n
DP[0] = 1  # 0が1番目
for i in range(n):
  for j in S:
    if i+j > n-1:
      continue #list外となる
    else:
      DP[i+j] = (DP[i+j] + DP[i]) % 998244353

ans = DP[n-1] % 998244353

#print(LR)
#print(S)
#print(DP)
print(ans)