MOD = 998244353 
N, K = [int(i) for i in input().split()]
k = []
vals = []
for i in range(K):
  v = [int(i) for i in input().split()]
  vals.extend([*range(v[0], v[1] + 1)])
  
vals.sort()

d  = {}

def helper(n):
  if n == 0:
    return 1
  if n in d:
    return d[n]
  if n < vals[0]:
    return -1
  count = 0
  for v in vals:
    r = helper(n - v)
    if r != -1:
      count += r
      count %= MOD
  d[n] = count
  return int(count)
 
print(helper(N - 1))