# -*- coding: utf-8 -*-
N, K = map(int, input().split())
D = []
S = []
T = []
mod = 998244353
for i in range(K):
  D.append(list(map(int, input().split())))
  while(D[i][0] <= D[i][1]):
    S.append(D[i][0])
    D[i][0] += 1

def func(x,S,T):
  for i in range(len(T)):
    if x == T[i][0]:
      return T[i][1]
  count = 0
  for t in S:
    if x-t > 1:
      count += func(x-t,S,T)
    elif x-t == 1:
      count += 1
  T.append((x,count))
  return count

print(func(N,S,T)%mod)