N,K = [int(i) for i in input().split()]
mod = 998244353
LR = []
S = []
dp = [0]*(N+1)
dps = [0]*(N+1)
dps[1] = 1
for i in range(K):
  LR.append([int(i) for i in input().split()])
rM = 0
for i in range(N):
  for lr in LR:
    if lr[0] <= i and i <= lr[1]:
      S.append(i)
  rM = max(rM, lr[1])
for i in range(1,N):
  if i in S:
    dp[i] = 1
  for l,r in LR:
    l,r = i - r,i - l
    if r < 1:
      continue
    l = max(0,l)
    dp[i] += dps[r] - dps [l-1]
    dp[i] %= mod
    dps[i] += dps[r] - dps[l]
    
  dps[i] = dps[i-1] + dp[i]
print(dp[-2])