N, K = map(int, input().split())
numl = []
for i in range(K):
  l, r = map(int, input().split())
  numl = numl + list(range(l, r+1))
numl.sort()
#print(numl)
ans = [0] * N
ans[0] = 1
for i in range(N-1):
  for j in numl:
    if i + j < N:
      ans[i + j] = (ans[i + j] + ans[i]) % 998244353
    else:
      break
print(ans[N-1])