import numpy as np
import numba
from numba import jit, b1, i4, i8, f8

N,K = map(int, input().split())

MOD = 998244353

lst = np.zeros((K, 2), np.int64)
for _ in range(K):
  l, r = map(int, input().split())
  lst[_][0]  = l
  lst[_][1] = r
    

'''dp = np.zeros((N*2), int)
dp[0] = 1

for i in range(N):
  a = dp[i] % MOD
  for l, r in lst:
    dp[i+l:i+r+1] += a
  #print(dp)
'''
  
@jit((i8, i8[:]), cache=True)
def main(N_, lst_):
  dp = np.zeros((N_*2), int)
  dp[0] = 1
  for i in range(N_):
    a = dp[i] % MOD
    for l, r in lst_:
      dp[i+l:i+r+1] += a
  return dp[N_ - 1] % MOD


print(main(N, lst))
