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

S = set()
for _ in range(K):
  l, r = map(int, input().split())
  S |= set(range(l, r + 1))

D = [0] * N
D[0] = 1

for n in range(N):
  for i in range(n):
    if (n - i) in S:
      D[n] += D[i] % 998244353
      
print(D[N - 1] % 998244353)