N, K = map(int, input().split())
L = [0]*K
R = [0]*K
for i in range(K):
  L[i], R[i] = map(int, input().split())
  R[i] += 1

M = 998244353
T = [0]*N
T[0] = 1
s = 0
for i in range(N):
  s += T[i]
  for j in range(K):
    if i+L[j]<N:
      T[i+L[j]] += s
      T[i+L[j]] %= M
    if i+R[j]<N:
      T[i+R[j]] -= s
      T[i+R[j]] %= M

print(T[-1])
