import numpy as np

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

a_array = array = np.zeros(N)
for k in range(K):
  L, R = map(int, input().split())
  a1 = np.zeros(L-1)
  a2 = np.ones(R-L+1)
  a3 = np.zeros(N-R)
  a = np.concatenate([a1, a2, a3], 0)
  a_array += a
a_array = np.where(a_array > 0, 1, 0)


array = np.zeros(N)
array[0] = 1
for i in range(N):
  if i == 0:
    pass
  else:
    p = int(i)
    calc = a_array[:p]
    total = np.sum(array[:p] * calc[::-1])
    array[p] = total
g = 998244353
print(int(array[-1]) % g)