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